Part Number Hot Search : 
M5229 101MF 2SK3335 PTZ24B SCPAS05F AN78N06 170CA 215DH
Product Description
Full Text Search
 

To Download PIC16F648A-ISOC06 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2009 microchip technology inc. ds40044g pic16f627a/628a/648a data sheet flash-based, 8-bit cmos microcontrollers with nanowatt technology downloaded from: http:///
ds40044g-page 2 ? 2009 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyers risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, rfpic and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mxdev, mxlab, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, octopus, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, pic 32 logo, real ice, rflab, select mode, total endurance, tsharc, uniwin driver, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2009, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: microchip products meet the specification cont ained in their particular microchip data sheet. microchip believes that its family of products is one of the most secure families of its kind on the market today, when used i n the intended manner and under normal conditions. there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip products in a manner outside the operating specifications contained in microchips data sheets. most likely, the person doing so is engaged in theft of intellectual property. microchip is willing to work with the customer who is concerned about the integrity of their code. neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as unbreakable. code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchips c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory an d analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 3 pic16f627a/628a/648a high-performance risc cpu: operating speeds from dc C 20 mhz interrupt capability 8-level deep hardware stack direct, indirect and relative addressing modes 35 single-word instructions: - all instructions single cycle except branches special microcontroller features: internal and external oscillator options: - precision internal 4 mhz oscillator factory calibrated to 1% - low-power internal 48 khz oscillator - external oscillator support for crystals and resonators power-saving sleep mode programmable weak pull-ups on portb multiplexed master clear/input-pin watchdog timer with independent oscillator for reliable operation low-voltage programming in-circuit serial programming? (via two pins) programmable code protection brown-out reset power-on reset power-up timer and oscillator start-up timer wide operating voltage range (2.0-5.5v) industrial and extended temperature range high-endurance flash/eeprom cell: - 100,000 write flash endurance - 1,000,000 write eeprom endurance - 40 year data retention low-power features: standby current: - 100 na @ 2.0v, typical operating current: -12 a @ 32 khz, 2.0v, typical -120 a @ 1 mhz, 2.0v, typical watchdog timer current: -1 a @ 2.0v, typical timer1 oscillator current: -1.2 a @ 32 khz, 2.0v, typical dual-speed internal oscillator: - run-time selectable between 4 mhz and 48 khz -4 s wake-up from sleep, 3.0v, typical peripheral features: 16 i/o pins with individual direction control high current sink/source for direct led drive analog comparator module with: - two analog comparators - programmable on-chip voltage reference (v ref ) module - selectable internal or external reference - comparator outputs are externally accessible timer0: 8-bit timer/counter with 8-bit programmable prescaler timer1: 16-bit timer/counter with external crystal/ clock capability timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler capture, compare, pwm module: - 16-bit capture/compare -10-bit pwm addressable universal synchronous/asynchronous receiver/transmitter usart/sci device program memory data memory i/o ccp (pwm) usart comparators timers 8/16-bit flash (words) sram (bytes) eeprom (bytes) pic16f627a 1024 224 128 16 1 y 2 2/1 pic16f628a 2048 224 128 16 1 y 2 2/1 pic16f648a 4096 256 256 16 1 y 2 2/1 18-pin flash-based, 8-bi t cmos microcontrollers with nanowatt technology downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 4 ? 2009 microchip technology inc. pin diagrams 1918 16 15 14 13 12 11 17 20 pdip, soic ssop 27a/628a/648a ra6/osc2/clkout ra7/osc1/clkin v ss v ss v dd v dd ra1/an1 ra0/an0 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd rb1/rx/dt rb2/tx/ck rb3/ccp1 rb4/pgm rb5 ra3/an3/cmp1 ra4/t0cki/cmp2 ra5/mclr /v pp rb0/int ra2/an2/v ref v ss rb1/rx/dt rb2/tx/ck rb3/ccp1 ra3/an3/cmp1 ra4/t0cki/cmp2 ra5/mclr /v pp rb0/int ra2/an2/v ref ra6/osc2/clkout ra7/osc1/clkin v dd ra1/an1 ra0/an0 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd rb4/pgm rb5 pic16f627a/628a/648a nc nc 2827 26 25 24 23 12 3 4 5 6 7 89 1011 22 2120 19 18 17 16 15 14 13 12 ra2/an2/v ref ra3/an3/cmp1 ra4/t0cki/cmp2 ra5/mclr /v pp v ss rb0/int rb1/rx/dt rb2/tx/ck rb3/ccp1 ra1/an1 ra0/an0 ra7/osc1/clkin ra6/osc2/clkout rb7/t1osi/pgd rb6/t1oso/t1cki/pgc rb5 v dd rb4/pgm v ss ncnc nc nc nc nc v dd pic16f627a/628a pic16f648a 28-pin qfn 2 3 4 5 6 7 8 9 11 8 1715 14 13 12 11 10 16 2 3 4 5 6 7 8 9 10 1 pic16f627a/628a/648a downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 5 pic16f627a/628a/648a table of contents 1.0 general description ........................................... ................................................... .......... ................................................................ 7 2.0 pic16f627a/628a/648a device varieties................................... ................................................... ................................................ 9 3.0 architectural overview ............................................................... ...................................... ............................................................. 11 4.0 memory organization ......................................... ................................................... ........... ............................................................. 17 5.0 i/o ports....................................................................................... ........................... ...................................................................... 33 6.0 timer0 module ............................................. ................................................... ............. ................................................................. 47 7.0 timer1 module ............................................. ................................................... ............. ................................................................. 50 8.0 timer2 module ............................................. ................................................... .............. ................................................................ 54 9.0 capture/compare/pwm (ccp) module ................................. .......................................................... ............................................. 57 10.0 comparator module ........................................... ................................................... ........... ........................................................... 63 11.0 voltage reference module ......................................... ................................................... ...... ....................................................... 69 12.0 universal synchronous asynchr onous receiver transmitter (usart) module..................................... ............... ..................... 73 13.0 data eeprom memory ........................................................................ ............................... ....................................................... 91 14.0 special features of the cpu ..................................................... .......................................... ....................................................... 97 15.0 instruction set summary.......................................................... ......................................... ........................................................ 117 16.0 development support ............................................ ................................................... ....... ......................................................... 131 17.0 electrical specifications ......................................... ....................................................... ............................................................ 135 18.0 dc and ac characteristics graphs and tables ................................... ............................................ ........................................ 151 19.0 packaging information ............................................................... ............................................................................................... 16 3 appendix a: data sheet revision history.................................... ................................................... . ................................................. 171 appendix b: device differences ........................................... ................................................... ... ...................................................... 171 appendix c: device migrations .......................................... ................................................... ..... ....................................................... 172 appendix d: migrating from other pic ? devices ................................................................................ ....................................... ....... 172 the microchip web site ................................................... ..................................................... ............................................................ 173 customer change notification service ....................................... ................................................... . .................................................. 173 customer support............................................... ................................................... ............. .............................................................. 173 reader response ................................................. ................................................... ............ ............................................................. 174 product identification system ................................................. ..................................................................................................... ..... 179 to our valued customers it is our intention to provide our valued customers with the bes t documentation possible to ensure successful use of your micro - chip products. to this end, we will continue to improve our pub lications to better suit your needs. our publications will be re fined and enhanced as new volumes and updates are introduced. if you have any questions or comments regard ing this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: microchips worldwide web site; http://www.microchip.com your local microchip sales office (see last page) when contacting a sales office, please specify which device, revision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 6 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 7 pic16f627a/628a/648a 1.0 general description the pic16f627a/628a/648a are 18-pin flash-based members of the versatile pic16f627a/628a/648a family of low-cost, high-performance, cmos, fully- static, 8-bit microcontrollers. all pic ? microcontrollers employ an advanced risc architecture. the pic16f627a/628a/648a have enhanced core features, an eight-level deep stack, and multiple internal and external interrupt sources. the separate instruction and data buses of the harvard architecture allow a 14-bit wide instruction word with the separate 8-bit wide data. the two-stage instruction pipeline allows all instructions to execute in a single- cycle, except for program branches (which require two cycles). a total of 35 instructions (reduced instruction set) are available, complemented by a large register set. pic16f627a/628a/648a microcontrollers typically achieve a 2:1 code compression and a 4:1 speed improvement over other 8-bit microcontrollers in their class. pic16f627a/628a/648a devices have integrated features to reduce external components, thus reducing system cost, enhancing system reliability and reducing power consumption. the pic16f627a/628a/648a has 8 oscillator configurations. the single-pin rc oscillator provides a low-cost solution. the lp oscillator minimizes power consumption, xt is a standard crystal, and intosc is a self-contained precision two-speed internal oscillator. the hs mode is for high-speed crystals. the ec mode is for an external clock source. the sleep (power-down) mode offers power savings. users can wake-up the chip from sleep through several external interrupts, internal interrupts and resets. a highly reliable watchdog timer with its own on-chip rc oscillator provides protection against software lock- up. table 1-1 shows the features of the pic16f627a/628a/ 648a mid-range microcontroller family. a simplified block diagram of the pic16f627a/628a/ 648a is shown in figure 3-1. the pic16f627a/628a/648a series fits in applications ranging from battery chargers to low power remote sensors. the flash technology makes customizing application programs (detection levels, pulse genera- tion, timers, etc.) extremely fast and convenient. the small footprint packages makes this microcontroller series ideal for all applications with space limitations. low cost, low power, high performance, ease of use and i/o flexibility make the pic16f627a/628a/648a very versatile. 1.1 development support the pic16f627a/628a/648a family is supported by a full-featured macro assembler, a software simulator, an in-circuit emulator, a low cost in-circuit debugger, a low cost development programmer and a full-featured programmer. a third party c compiler support tool is also available. table 1-1: pic16f627a/628a/648a family of devices pic16f627a pic16f628a pic16f648a pic16lf627a pic16lf628a pic16lf648a clock maximum frequency of operation (mhz) 20 20 20 20 20 20 flash program memory (words) 1024 2048 4096 1024 2048 4096 memory ram data memory (bytes) 224 224 256 224 224 256 eeprom data memory (bytes) 128 128 256 128 128 256 timer module(s) tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 tmr0, tmr1, tmr2 c o m p a r a t o r ( s ) 222222 peripherals capture/compare/ pwm modules 111111 serial communications usart usart usart usart usart usart internal voltage reference yes yes yes ye s ye s ye s i n t e r r u p t s o u r c e s1 01 01 01 01 01 0 i/o pins 16 16 16 16 16 16 features voltage range (volts) 3.0-5.5 3.0-5.5 3.0-5.5 2.0-5.5 2.0-5.5 2.0-5.5 brown-out reset yes yes yes yes yes yes packages 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn 18-pin dip, soic, 20-pin ssop, 28-pin qfn all pic ? family devices have power-on reset, selectable watchdog time r, selectable code-protect and high i/o current capability. all pic16f627a/628a/648a family devices use serial programming with clock pin rb6 and data pi n rb7. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 8 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 9 pic16f627a/628a/648a 2.0 pic16f627a/628a/648a device varieties a variety of frequency ranges and packaging options are available. depending on application and production requirements, the proper device option can be selected using the information in the pic16f627a/628a/648a product identification system, at the end of this data sheet. when placing orders, please use this page of the data sheet to specify the correct part number. 2.1 flash devices flash devices can be erased and re-programmed electrically. this allows the same device to be used for prototype development, pilot programs and production. a further advantage of the electrically erasable flash is that it can be erased and reprogrammed in-circuit, or by device programmers, such as microchips picstart ? plus or pro mate ? ii programmers. 2.2 quick-turnaround-production (qtp) devices microchip offers a qtp programming service for factory production orders. this service is made available for users who chose not to program a medium to high quantity of units and whose code patterns have stabilized. the devices are standard flash devices, but with all program locations and configuration options already programmed by the factory. certain code and prototype verification procedures apply before production shipments are available. please contact your microchip technology sales office for more details. 2.3 serialized quick-turnaround- production (sqtp sm ) devices microchip offers a unique programming service where a few user-defined locations in each device are programmed with different serial numbers. the serial numbers may be random, pseudo-random or sequential. serial programming allows each device to have a unique number, which can serve as an entry-code, password or id number. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 10 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 11 pic16f627a/628a/648a 3.0 architectural overview the high performance of the pic16f627a/628a/648a family can be attributed to a number of architectural features commonly found in risc microprocessors. to begin with, the pic16f627a/628a/648a uses a harvard architecture in which program and data are accessed from separate memories using separate busses. this improves bandwidth over traditional von neumann architecture where program and data are fetched from the same memory. separating program and data memory further allows instructions to be sized differently than 8-bit wide data word. instruction opcodes are 14-bits wide making it possible to have all single-word instructions. a 14-bit wide program mem- ory access bus fetches a 14-bit instruction in a single cycle. a two-stage pipeline overlaps fetch and execu- tion of instructions. consequently, all instructions (35) execute in a single-cycle (200 ns @ 20 mhz) except for program branches. table 3-1 lists device memory sizes (flash, data and eeprom). table 3-1: device memory list the pic16f627a/628a/648a can directly or indirectly address its register files or data memory. all special function registers (sfr), including the program counter, are mapped in the data memory. the pic16f627a/628a/648a have an orthogonal (symmet- rical) instruction set that makes it possible to carry out any operation, on any register, using any addressing mode. this symmetrical nature and lack of special optimal situations makes programming with the pic16f627a/628a/648a simple yet efficient. in addition, the learning curve is reduced significantly. the pic16f627a/628a/648a devices contain an 8-bit alu and working register. the alu is a general purpose arithmetic unit. it performs arithmetic and boolean functions between data in the working register and any register file. the alu is 8-bits wide and capable of addition, subtraction, shift and logical operations. unless otherwise mentioned, arithmetic operations are twos complement in nature. in two-operand instructions, typically one operand is the working register (w register). the other operand is a file register or an immediate constant. in single operand instructions, the operand is either the w register or a file register. the w register is an 8-bit working register used for alu operations. it is not an addressable register. depending on the instruction executed, the alu may affect the values of the carry (c), digit carry (dc), and zero (z) bits in the status register. the c and dc bits operate as borrow and digit borrow out bits, respectively, in subtraction. see the sublw and subwf instructions for examples. a simplified block diagram is shown in figure 3-1, and a description of the device pins in table 3-2. two types of data memory are provided on the pic16f627a/628a/648a devices. nonvolatile eeprom data memory is provided for long term storage of data, such as calibration values, look-up table data, and any other data which may require periodic updating in the field. these data types are not lost when power is removed. the other data memory provided is regular ram data memory. regular ram data memory is provided for temporary storage of data during normal operation. data is lost when power is removed. device memory flash program ram data eeprom data pic16f627a 1024 x 14 224 x 8 128 x 8 pic16f628a 2048 x 14 224 x 8 128 x 8 pic16f648a 4096 x 14 256 x 8 256 x 8 pic16lf627a 1024 x 14 224 x 8 128 x 8 pic16lf628a 2048 x 14 224 x 8 128 x 8 pic16lf648a 4096 x 14 256 x 8 256 x 8 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 12 ? 2009 microchip technology inc. figure 3-1: block diagram note 1: higher order bits are from the status register. flash program memory 13 data bus 8 14 program bus instruction reg program counter 8-level stack (13-bit) ram file registers direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clkin osc2/clkout mclr v dd , v ss porta portb ra4/t0ck1/cmp2 ra5/mclr /v pp rb0/int 8 8 brown-out reset usart ccp1 timer0 timer1 timer2 ra3/an3/cmp1 ra2/an2/v ref ra1/an1 ra0/an0 8 3 rb1/rx/dt rb2/tx/ck rb3/ccp1 rb4/pgm rb5 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd low-voltage programming ra6/osc2/clkout ra7/osc1/clkin v ref comparator data eeprom downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 13 pic16f627a/628a/648a table 3-2: pic16f627a/628a/648a pinout description name function input type output type description ra0/an0 ra0 st cmos bidirectional i/o port an0 an analog comparator input ra1/an1 ra1 st cmos bidirectional i/o port an1 an analog comparator input ra2/an2/v ref ra2 st cmos bidirectional i/o port an2 an analog comparator input v ref a n v ref output ra3/an3/cmp1 ra3 st cmos bidirectional i/o port an3 an analog comparator input cmp1 cmos comparator 1 output ra4/t0cki/cmp2 ra4 st od bidirectional i/o port t0cki st timer0 clock input cmp2 od comparator 2 output ra5/mclr /v pp ra5 st input port mclr st master clear. when configured as mclr , this pin is an active low reset to the device. voltage on mclr /v pp must not exceed v dd during normal device operation. v pp programming voltage input ra6/osc2/clkout ra6 st cmos bidirectional i/o port osc2 xtal oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. clkout cmos in rc/intosc mode, osc2 pin can output clkout, which has 1/4 the frequency of osc1. ra7/osc1/clkin ra7 st cmos bidirectional i/o port osc1 xtal oscillator crystal input clkin st external clock source input. rc biasing pin. rb0/int rb0 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. int st external interrupt rb1/rx/dt rb1 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. rx st usart receive pin dt st cmos synchronous data i/o rb2/tx/ck rb2 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. tx cmos usart transmit pin ck st cmos synchronous clock i/o rb3/ccp1 rb3 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. ccp1 st cmos capture/compare/pwm i/o legend: o = output cmos = cmos output p = power = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 14 ? 2009 microchip technology inc. rb4/pgm rb4 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. pgm st low-voltage programming input pin. when low-voltage programming is enabled, the interrupt-on-pin change and weak pull-up resistor are disabled. rb5 rb5 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. rb6/t1oso/t1cki/pgc rb6 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1oso xtal timer1 oscillator output t1cki st timer1 clock input pgc st icsp? programming clock rb7/t1osi/pgd rb7 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1osi xtal timer1 oscillator input pgd st cmos icsp data i/o v ss v ss power ground reference for logic and i/o pins v dd v dd power positive supply for logic and i/o pins table 3-2: pic16f627a/628a/648a pinout description (continued) name function input type output type description legend: o = output cmos = cmos output p = power = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 15 pic16f627a/628a/648a 3.1 clocking scheme/instruction cycle the clock input (ra7/osc1/clkin pin) is internally divided by four to generate four non-overlapping quadrature clocks namely q1, q2, q3 and q4. internally, the program counter (pc) is incremented every q1, the instruction is fetched from the program memory and latched into the instruction register in q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow is shown in figure 3-2. 3.2 instruction flow/pipelining an instruction cycle consists of four q cycles (q1, q2, q3 and q4). the instruction fetch and execute are pipelined such that fetch takes one instruction cycle while decode and execute takes another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction causes the program counter to change (e.g., goto ) then two cycles are required to complete the instruction (example 3-1). a fetch cycle begins with the program counter incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 3-2: clock /instruction cycle example 3-1: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1q2 q3 q4 pc clkout pc pc + 1 pc + 2 fetch inst (pc) execute inst (pc - 1) fetch inst (pc + 1) execute inst (pc) fetch inst (pc + 2) execute inst (pc + 1) internal phase clock note: all instructions are single cycle except for any program branches. these take two c ycles since the fetch instruction is flushed from the pipeline while the new instructio n is being fetched and then executed. 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. call sub_1 fetch 3 execute 3 4. bsf porta, 3 fetch 4 flush fetch sub_1 execute sub_1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 16 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 17 pic16f627a/628a/648a 4.0 memory organization 4.1 program memory organization the pic16f627a/628a/648a has a 13-bit program counter capable of addressing an 8k x 14 program memory space. only the first 1k x 14 (0000h-03ffh) for the pic16f627a, 2k x 14 (0000h-07ffh) for the pic16f628a and 4k x 14 (0000h-0fffh) for the pic16f648a are physically implemented. accessing a location above these boundaries will cause a wrap- around within the first 1k x 14 space (pic16f627a), 2k x 14 space (pic16f628a) or 4k x 14 space (pic16f648a). the reset vector is at 0000h and the interrupt vector is at 0004h (figure 4-1). figure 4-1: program memory map and stack 4.2 data memory organization the data memory (figure 4-2 and figure 4-3) is partitioned into four banks, which contain the general purpose registers (gprs) and the special function registers (sfrs). the sfrs are located in the first 32 locations of each bank. there are general purpose registers implemented as static ram in each bank. table 4-1 lists the general purpose register available in each of the four banks. table 4-1: general purpose static ram registers addresses f0h-ffh, 170h-17fh and 1f0h-1ffh are implemented as common ram and mapped back to addresses 70h-7fh. table 4-2 lists how to access the four banks of registers via the status register bits rp1 and rp0. table 4-2: access to banks of registers 4.2.1 general purpose register file the register file is organized as 224 x 8 in the pic16f627a/628a and 256 x 8 in the pic16f648a. each is accessed either directly or indirectly through the file select register (fsr), see section 4.4 indirect addressing, indf and fsr registers . pc<12:0> 13 000h 0004 0005 03ffh 1fffh stack level 1 stack level 8 reset vector interrupt vector on-chip program memory call, returnretfie, retlw stack level 2 07ffh pic16f627a, pic16f628a and pic16f648a on-chip program memory pic16f628a and pic16f648a on-chip program memory pic16f648a only 0fffh pic16f627a/628a pic16f648a bank0 20-7fh 20-7fh bank1 a0h-ff a0h-ff bank2 120h-14fh, 170h-17fh 120h-17fh bank3 1f0h-1ffh 1f0h-1ffh bank rp1 rp0 0 00 1 01 2 10 3 11 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 18 ? 2009 microchip technology inc. figure 4-2: data memory map of the pic16f627a and pic16f628a indirect addr. (1) tmr0 pcl status fsr porta portb pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h ccp1con option pcl status fsr trisa trisb pclath intcon pie1 pcon pr2 00h01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1fh 80h81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 unimplemented data memory locations, read as 0 . note 1: not a physical register. file address indirect addr. (1) indirect addr. (1) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 10ch 10dh 10eh 10fh 180h181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 18ch 18dh 18eh 18fh 17fh 1ffh bank 2 bank 3 indirect addr. (1) tmr0 option rcsta txreg rcreg cmcon txsta spbrg vrcon general purpose register 1efh 1f0h accesses 70h-7fh efh f0h accesses 70h-7fh 16fh 170h accesses 70h-7fh 80 bytes eedata eeadr eecon1 eecon2 (1) general purpose register 80 bytes general purpose register 48 bytes 11fh 120h 14fh 150h 6fh 70h 16 bytes portb trisb 1ch1dh 1eh downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 19 pic16f627a/628a/648a figure 4-3: data memory map of the pic16f648a indirect addr. (1) tmr0 pcl status fsr porta portb pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con ccpr1l ccpr1h ccp1con option pcl status fsr trisa trisb pclath intcon pie1 pcon pr2 00h01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1fh 80h81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 unimplemented data memory locations, read as 0 . note 1: not a physical register. file address indirect addr. (1) indirect addr. (1) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 10ch 10dh 10eh 10fh 180h181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 18ch 18dh 18eh 18fh 17fh 1ffh bank 2 bank 3 indirect addr. (1) tmr0 option rcsta txreg rcreg cmcon txsta spbrg vrcon general purpose register 1efh 1f0h accesses 70h-7fh efh f0h accesses 70h-7fh 16fh 170h accesses 70h-7fh 80 bytes eedata eeadr eecon1 eecon2 (1) general purpose register 80 bytes 11fh 120h 6fh 70h 16 bytes portb trisb 1ch1dh 1eh general purpose register 80 bytes downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 20 ? 2009 microchip technology inc. 4.2.2 special function registers the sfrs are registers used by the cpu and periph- eral functions for controlling the desired operation of the device (table 4-3). these registers are static ram. the special registers can be classified into two sets (core and peripheral). the sfrs associated with the core functions are described in this section. those related to the operation of the peripheral features are described in the section of that peripheral feature. table 4-3: special registers summary bank0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 0 00h indf addressing this location uses contents of fsr to address data memory (not a physical registe r) xxxx xxxx 30 01h tmr0 timer0 modules register xxxx xxxx 47 02h pcl program counters (pc) least significant byte 0000 0000 30 03h status irp rp1 rp0 to pd zd c c 0001 1xxx 24 04h fsr indirect data memory address pointer xxxx xxxx 30 05h porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx 0000 33 06h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 38 07h unimplemented 08h unimplemented 09h unimplemented 0ah pclath write buffer for upper 5 bits of program counter ---0 0000 30 0bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 26 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 28 0dh unimplemented 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx 50 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx 50 10h t1con t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 50 11h tmr2 tmr2 modules register 0000 0000 54 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 54 13h unimplemented 14h unimplemented 15h ccpr1l capture/compare/pwm register (lsb) xxxx xxxx 57 16h ccpr1h capture/compare/pwm register (msb) xxxx xxxx 57 17h ccp1con ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 57 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 74 19h txreg usart transmit data register 0000 0000 79 1ah rcreg usart receive data register 0000 0000 82 1bh unimplemented 1ch unimplemented 1dh unimplemented 1eh unimplemented 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 63 legend: - = unimplemented locations read as 0 , u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14- 7. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 21 pic16f627a/628a/648a table 4-4: special function registers summary bank1 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 1 80h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 30 81h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 25 82h pcl program counters (pc) least significant byte 0000 0000 30 83h status irp rp1 rp0 to pd zd cc 0001 1xxx 24 84h fsr indirect data memory address pointer xxxx xxxx 30 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 33 86h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 38 87h unimplemented 88h unimplemented 89h unimplemented 8ah pclath write buffer for upper 5 bits of program counter ---0 0000 30 8bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 26 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 27 8dh unimplemented 8eh pcon oscf p o r bor ---- 1-0x 29 8fh unimplemented 90h unimplemented 91h unimplemented 92h pr2 timer2 period register 1111 1111 54 93h unimplemented 94h unimplemented 95h unimplemented 96h unimplemented 97h unimplemented 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 73 99h spbrg baud rate generator register 0000 0000 75 9ah eedata eeprom data register xxxx xxxx 91 9bh eeadr eeprom address register xxxx xxxx 92 9ch eecon1 wrerr wren wr rd ---- x000 92 9dh eecon2 eeprom control register 2 (not a physical register) ---- ---- 92 9eh unimplemented 9fh vrcon vren vroe vrr vr3 vr2 vr1 vr0 000- 0000 69 legend: - = unimplemented locations read as 0 , u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14- 7. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 22 ? 2009 microchip technology inc. table 4-5: special function registers summary bank2 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 2 100h indf addressing this location uses contents of fsr to address data memory (not a physical re gister) xxxx xxxx 30 101h tmr0 timer0 modules register xxxx xxxx 47 102h pcl program counters (pc) least significant byte 0000 0000 30 103h status irp rp1 rp0 to pd zd cc 0001 1xxx 24 104h fsr indirect data memory address pointer xxxx xxxx 30 105h unimplemented 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 38 107h unimplemented 108h unimplemented 109h unimplemented 10ah pclath write buffer for upper 5 bits of program counter ---0 0000 30 10bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 26 10ch unimplemented 10dh unimplemented 10eh unimplemented 10fh unimplemented 110h unimplemented 111h unimplemented 112h unimplemented 113h unimplemented 114h unimplemented 115h unimplemented 116h unimplemented 117h unimplemented 118h unimplemented 119h unimplemented 11ah unimplemented 11bh unimplemented 11ch unimplemented 11dh unimplemented 11eh unimplemented 11fh unimplemented legend: - = unimplemented locations read as 0 , u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented. note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14- 7. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 23 pic16f627a/628a/648a table 4-6: special function registers summary bank3 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset (1) details on page bank 3 180h indf addressing this location uses contents of fsr to address data memory (not a physical register ) xxxx xxxx 30 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 25 182h pcl program counters (pc) least significant byte 0000 0000 30 183h status irp rp1 rp0 to pd zd cc 0001 1xxx 24 184h fsr indirect data memory address pointer xxxx xxxx 30 185h unimplemented 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 38 187h unimplemented 188h unimplemented 189h unimplemented 18ah pclath write buffer for upper 5 bits of program counter ---0 0000 30 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 26 18ch unimplemented 18dh unimplemented 18eh unimplemented 18fh unimplemented 190h unimplemented 191h unimplemented 192h unimplemented 193h unimplemented 194h unimplemented 195h unimplemented 196h unimplemented 197h unimplemented 198h unimplemented 199h unimplemented 19ah unimplemented 19bh unimplemented 19ch unimplemented 19dh unimplemented 19eh unimplemented 19fh unimplemented legend: - = unimplemented locations read as 0 , u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: for the initialization condition for registers tables, refer to table 14-6 and table 14- 7. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 24 ? 2009 microchip technology inc. 4.2.2.1 status register the status register, shown in register 4-1, contains the arithmetic status of the alu; the reset status and the bank select bits for data memory (sram). the status register can be the destination for any instruction, like any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are non- writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper-three bits and set the z bit. this leaves the status register as ?000uu1uu? (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register because these instructions do not affect any status bit. for other instructions, not affecting any status bits, see the instruction set summary. register 4-1: status C status register (address: 03h, 83h, 103h, 183h) note: the c and dc bits operate as a borrow and digit borrow out bit, respectively, in subtraction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zd cc bit 7 bit 0 bit 7 irp : register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h-1ffh) 0 = bank 0, 1 (00h-ffh) bit 6-5 rp<1:0> : register bank select bits (used for direct addressing) 00 = bank 0 (00h-7fh) 01 = bank 1 (80h-ffh) 10 = bank 2 (100h-17fh) 11 = bank 3 (180h-1ffh) bit 4 to : time out bit 1 = after power-up, clrwdt instruction or sleep instruction 0 = a wdt time out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z : zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc : digit carry/bo rrow bit ( addwf , addlw,sublw,subwf instructions) (for bo rrow the polarity is reversed) 1 = a carry-out from the 4th low order bit of the result occurred 0 = no carry-out from the 4th low order bit of the result bit 0 c : carry/bo rrow bit ( addwf , addlw,sublw,subwf instructions) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for bo rrow , the polarity is reversed. a subtraction is executed by adding the twos complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 25 pic16f627a/628a/648a 4.2.2.2 option register the option register is a readable and writable register, which contains various control bits to configure the tmr0/wdt prescaler, the external rb0/int interrupt, tmr0 and the weak pull-ups on portb. register 4-2: option_reg C option register (address: 81h, 181h) note: to achieve a 1:1 prescaler assignment for tmr0, assign the prescaler to the wdt (psa = 1 ). see section 6.3.1 switching prescaler assignment . r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg : interrupt edge select bit 1 = interrupt on rising edge of rb0/int pin 0 = interrupt on falling edge of rb0/int pin bit 5 t0cs : tmr0 clock source select bit 1 = transition on ra4/t0cki/cmp2 pin 0 = internal instruction cycle clock (clkout) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/t0cki/cmp2 pin 0 = increment on low-to-high transition on ra4/t0cki/cmp2 pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0> : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown 000001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 26 ? 2009 microchip technology inc. 4.2.2.3 intcon register the intcon register is a readable and writable register, which contains the various enable and flag bits for all interrupt sources except the comparator module. see section 4.2.2.4 pie1 register and section 4.2.2.5 pir1 register for a description of the comparator enable and flag bits. register 4-3: intcon C interrupt control register (address: 0bh, 8bh, 10bh, 18bh) note: interrupt flag bits get set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie t0ie inte rbie t0if intf rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all un-masked interrupts 0 = disables all interrupts bit 6 peie : peripheral interrupt enable bit 1 = enables all un-masked peripheral interrupts 0 = disables all peripheral interrupts bit 5 t0ie : tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 inte : rb0/int external interrupt enable bit 1 = enables the rb0/int external interrupt 0 = disables the rb0/int external interrupt bit 3 rbie : rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 t0if : tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf : rb0/int external interrupt flag bit 1 = the rb0/int external interrupt occurred (must be cleared in software) 0 = the rb0/int external interrupt did not occur bit 0 rbif : rb port change interrupt flag bit 1 = when at least one of the rb<7:4> pins changes state (must be cleared in software) 0 = none of the rb<7:4> pins have changed state legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 27 pic16f627a/628a/648a 4.2.2.4 pie1 register this register contains interrupt enable bits. register 4-4: pie1 C peripheral interrupt enable register 1 (address: 8ch) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 eeie: ee write complete interrupt enable bit 1 = enables the ee write complete interrupt 0 = disables the ee write complete interrupt bit 6 cmie : comparator interrupt enable bit 1 = enables the comparator interrupt 0 = disables the comparator interrupt bit 5 rcie : usart receive interrupt enable bit 1 = enables the usart receive interrupt 0 = disables the usart receive interrupt bit 4 txie : usart transmit interrupt enable bit 1 = enables the usart transmit interrupt 0 = disables the usart transmit interrupt bit 3 unimplemented : read as 0 bit 2 ccp1ie : ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie : tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie : tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 28 ? 2009 microchip technology inc. 4.2.2.5 pir1 register this register contains interrupt flag bits. register 4-5: pir1 C peripheral interrupt register 1 (address: 0ch) note: interrupt flag bits get set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r-0 r-0 u-0 r/w-0 r/w-0 r/w-0 eeif cmif rcif txif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 eeif: eeprom write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation has not completed or has not been started bit 6 cmif : comparator interrupt flag bit 1 = comparator output has changed 0 = comparator output has not changed bit 5 rcif : usart receive interrupt flag bit 1 = the usart receive buffer is full 0 = the usart receive buffer is empty bit 4 txif : usart transmit interrupt flag bit 1 = the usart transmit buffer is empty 0 = the usart transmit buffer is full bit 3 unimplemented : read as 0 bit 2 ccp1if : ccp1 interrupt flag bit capture mode 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode unused in this mode bit 1 tmr2if : tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if : tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 29 pic16f627a/628a/648a 4.2.2.6 pcon register the pcon register contains flag bits to differentiate between a power-on reset, an external mclr reset, wdt reset or a brown-out reset. register 4-6: pcon C power contro l register (address: 8eh) note: bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor is cleared, indicating a brown-out has occurred. the bor status bit is a dont care and is not necessarily predictable if the brown-out circuit is disabled (by clearing the boren bit in the configuration word). u-0 u-0 u-0 u-0 r/w-1 u-0 r/w-0 r/w-x oscf p o r bor bit 7 bit 0 bit 7-4 unimplemented: read as 0 bit 3 oscf : intosc oscillator frequency bit 1 = 4 mhz typical 0 = 48 khz typical bit 2 unimplemented : read as 0 bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 30 ? 2009 microchip technology inc. 4.3 pcl and pclath the program counter (pc) is 13-bits wide. the low byte comes from the pcl register, which is a readable and writable register. the high byte (pc<12:8>) is not directly readable or writable and comes from pclath. on any reset, the pc is cleared. figure 4-4 shows the two situations for loading the pc. the upper example in figure 4-4 shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in figure 4-4 shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 4-4: loading of pc in different situations 4.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when doing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256-byte block). refer to the application note an556 implementing a table read (ds00556). 4.3.2 stack the pic16f627a/628a/648a family has an 8-level deep x 13-bit wide hardware stack (figure 4-1). the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return, retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 4.4 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf register. any instruction using the indf register actually accesses data pointed to by the file select register (fsr). reading indf itself indirectly will produce 00h. writing to the indf register indirectly results in a no-operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 4-5. a simple program to clear ram location 20h-2fh using indirect addressing is shown in example 4-1. example 4-1: indirect addressing pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu result goto, call opcode <10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl as destination note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call, return, retlw and retfie instructions, or the vectoring to an interrupt address. movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next ;yes continue downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 31 pic16f627a/628a/648a figure 4-5: direct/indirect a ddressing pic16f627a/628a/648a note: for memory map detail see figure 4-3, figure 4-2 and figure 4-1. ram indirect addressing direct addressing bank select location select rp1 rp0 6 0 from opcode irp fsr register 7 0 bank select location select 00 01 10 11 180h 1ffh 00h 7fh bank 0 bank 1 bank 2 bank 3 file registers status register status register downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 32 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 33 pic16f627a/628a/648a 5.0 i/o ports the pic16f627a/628a/648a have two ports, porta and portb. some pins for these i/o ports are multiplexed with alternate functions for the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. 5.1 porta and trisa registers porta is an 8-bit wide latch. ra4 is a schmitt trigger input and an open drain output. port ra4 is multiplexed with the t0cki clock input. ra5 (1) is a schmitt trigger input only and has no output drivers. all other ra port pins have schmitt trigger input levels and full cmos output drivers. all pins have data direction bits (tris registers) which can configure these pins as input or output. a 1 in the trisa register puts the corresponding output driver in a high-impedance mode. a 0 in the trisa register puts the contents of the output latch on the selected pin(s). reading the porta register reads the status of the pins whereas writing to it will write to the port latch. all write operations are read-modify-write operations. so a write to a port implies that the port pins are first read, then this value is modified and written to the port data latch. the porta pins are multiplexed with comparator and voltage reference functions. the operation of these pins are selected by control bits in the cmcon (comparator control register) register and the vrcon (voltage reference control register) register. when selected as a comparator input, these pins will read as 0 s. trisa controls the direction of the ra pins, even when they are being used as comparator inputs. the user must make sure to keep the pins configured as inputs when using them as comparator inputs. the ra2 pin will also function as the output for the voltage reference. when in this mode, the v ref pin is a very high-impedance output. the user must configure trisa<2> bit as an input and use high-impedance loads. in one of the comparator modes defined by the cmcon register, pins ra3 and ra4 become outputs of the comparators. the trisa<4:3> bits must be cleared to enable outputs to use this function. example 5-1: initializing porta figure 5-1: block diagram of ra0/an0:ra1/an1 pins note 1: ra5 shares function with v pp . when v pp voltage levels are applied to ra5, the device will enter programming mode. 2: on reset, the trisa register is set to all inputs. the digital inputs (ra<3:0>) are disabled and the comparator inputs are forced to ground to reduce current consumption. 3: trisa<6:7> is overridden by oscillator configuration. when porta<6:7> is overridden, the data reads 0 and the trisa<6:7> bits are ignored. clrf porta ;initialize porta by ;setting ;output data latches movlw 0x07 ;turn comparators off and movwf cmcon ;enable pins for i/o ;functions bcf status, rp1 bsf status, rp0 ;select bank1 movlw 0x1f ;value used to initialize ;data direction movwf trisa ;set ra<4:0> as inputs ;trisa<5> always;read as ?1?. ;trisa<7:6> ;depend on oscillator ;mode data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog i/o pin q d q ck input mode d q en to comparator schmitt trigger input buffer v dd v ss trisa (cmcon reg.) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 34 ? 2009 microchip technology inc. figure 5-2: blo ck diagram of ra2/an2/v ref pin figure 5-3: block diagram of the ra3/an3/cmp1 pin data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog ra2 pin q d q ck input mode d q en to comparator schmitt trigger input buffer vroe v ref v dd v ss trisa (cmcon reg.) data bus q d q ck wr porta wr trisa data latch tris latch rd rd porta analog ra3 pin q d q ck d q en to comparator schmitt trigger input buffer input mode comparator output comparator mode = 110 v dd v ss trisa (cmcon reg.) (cmcon reg.) 10 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 35 pic16f627a/628a/648a figure 5-4: block diagra m of ra4/t0cki/cmp2 pin figure 5-5: block diagram of the ra5/mclr /v pp pin figure 5-6: block diagram of ra6/osc2/clkout pin data bus q d q ck n wr porta wr trisa data latch tris latch rd trisa rd porta vss ra4 pin q d q ck d q en tmr0 clock input schmitt trigger input buffer comparator output comparator mode = 110 vss 10 (cmcon reg.) d q en hv detect mclr filter ra5/mclr /v pp mclr program mclre rd v ss data bus v ss porta rd circuit mode schmitt trigger input buffer trisa (configuration bit) wr d ck qq porta wr trisa v dd v ss clkout(f osc /4) f osc = 101, 111 (2) qd rd en rd porta f osc = d ck qq 011, 100, 110 (1) trisa from osc1 osc circuit note 1: intosc with ra6 = i/o or rc with ra6 = i/o. 2: intosc with ra6 = clkout or rc with ra6 = clkout. schmitt trigger input buffer data latch tris latch 10 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 36 ? 2009 microchip technology inc. figure 5-7: block diagra m of ra7/osc1/clkin pin data bus q d q ck wr porta wr trisa data latch tris latch rd trisa rd porta ra7/osc1/clkin pin q d q ck d q en to clock circuits f osc = 100 , 101 (1) v dd v ss note 1: intosc with clkout and intosc with i/o. schmitt trigger input buffer downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 37 pic16f627a/628a/648a table 5-1: porta functions table 5-2: summary of regist ers associated with porta name function input type output type description ra0/an0 ra0 st cmos bidirectional i/o port an0 an analog comparator input ra1/an1 ra1 st cmos bidirectional i/o port an1 an analog comparator input ra2/an2/v ref ra2 st cmos bidirectional i/o port an2 an analog comparator input v ref a nv ref output ra3/an3/cmp1 ra3 st cmos bidirectional i/o port an3 an analog comparator input cmp1 cmos comparator 1 output ra4/t0cki/cmp2 ra4 st od bidirectional i/o port. output is open drain type. t0cki st external clock input for tmr0 or comparator output cmp2 od comparator 2 output ra5/mclr /v pp ra5 st input port mclr st master clear. when configured as mclr , this pin is an active low reset to the device. voltage on mclr /v pp must not exceed v dd during normal device operation. v pp hv programming voltage input ra6/osc2/clkout ra6 st cmos bidirectional i/o port osc2 xtal oscillator crystal output. connects to crystal resonator in crystal oscillator mode. clkout cmos in rc or intosc mode. osc2 pin can output clkout, which has 1/4 the frequency of osc1. ra7/osc1/clkin ra7 st cmos bidirectional i/o port osc1 xtal oscillator crystal input. connects to crystal resonator in crystal oscillator mode. clkin st external clock source input. rc biasing pin. legend: o = output cmos = cmos output p = power = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 05h porta ra7 ra6 ra5 (1) ra4 ra3 ra2 ra1 ra0 xxxx 0000 qqqu 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 9fh vrcon vren vroe vrr vr3 vr2 vr1 vr0 000- 0000 000- 0000 legend: - = unimplemented locations read as 0 , u = unchanged, x = unknown, q = value depends on condition. shaded cells are not used for porta. note 1: mclre configuration bit sets ra5 functionality. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 38 ? 2009 microchip technology inc. 5.2 portb and trisb registers portb is an 8-bit wide bidirectional port. the corresponding data direction register is trisb. a 1 in the trisb register puts the corresponding output driver in a high-impedance mode. a 0 in the trisb register puts the contents of the output latch on the selected pin(s). portb is multiplexed with the external interrupt, usart, ccp module and the tmr1 clock input/output. the standard port functions and the alternate port functions are shown in table 5-3. alternate port functions may override the tris setting when enabled. reading portb register reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. so a write to a port implies that the port pins are first read, then this value is modified and written to the port data latch. each of the portb pins has a weak internal pull-up ( 200 a typical). a single control bit can turn on all the pull-ups. this is done by clearing the rbpu (option<7>) bit. the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on power-on reset. four of portbs pins, rb<7:4>, have an interrupt-on- change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb<7:4> pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb<7:4>) are compared with the old value latched on the last read of portb. the mismatch outputs of rb<7:4> are ored together to generate the rbif interrupt (flag latched in intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb. this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. this interrupt on mismatch feature, together with software configurable pull-ups on these four pins allow easy interface to a key pad and make it possible for wake-up on key-depression (see application note an552 implementing wake-up on key strokes? (ds00552). the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. figure 5-8: block diagram of rb0/int pin note: if a change on the i/o pin should occur when a read operation is being executed (start of the q2 cycle), then the rbif interrupt flag may not get set. data bus wr portb wr trisb rd portb data latch tris latch rb0/int int q d ck en qd en rd trisb rbpu p v dd v dd v ss q q d ck q weak pull-up schmitt ttl input buffer trigger downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 39 pic16f627a/628a/648a figure 5-9: blo ck diagram of rb1/rx/dt pin figure 5-10: block diagram of rb2/tx/ck pin data latch tris latch rd trisb q d q ck q d q ck 10 wr portb wr trisb schmitt trigger peripheral oe (1) data bus spen usart data output usart receive input rbpu v dd p en qd v dd v ss note 1: p eripheral oe (output enable) is only active if peripheral select is active. rd portb rx/dt rb1/ ttl input buffer weak pull-up data latch tris latch rd trisb q d q ck q d q ck 10 wr portb wr trisb schmitt trigger peripheral oe (1) data bus spen usart tx/ck output usart slave clock in rbpu v dd p en qd v dd v ss note 1: peripheral oe (output enable) is only active if peripheral select is active. rd portb ttl input buffer rb2/ tx/ck weak pull-up downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 40 ? 2009 microchip technology inc. figure 5-11: block diagram of rb3/ccp1 pin data latch tris latch rd trisb q d q ck q d q ck 01 wr portb wr trisb schmitt trigger peripheral oe (2) data bus ccp1con ccp output ccp in rbpu v dd p en qd v dd v ss note 1: peripheral oe (output enable) is only active if peripheral select is active. rd portb ttl input buffer rb3/ ccp1 weak pull-up downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 41 pic16f627a/628a/648a figure 5-12: block diag ram of rb4/pgm pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb schmitt trigger pgm input lvp data bus rb4/pgm v dd weak pull-up p from other qd en qd en set rbif rb<7:4> pins ttl input buffer v dd v ss note: the low-voltage programming disables the inte rrupt-on-change and the weak pull-ups on rb4. rbpu q1 q3 (configuration bit) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 42 ? 2009 microchip technology inc. figure 5-13: block di agram of rb5 pin data bus wr portb wr trisb rd portb data latch tris latch rb5 pin ttl input buffer rd trisb rbpu p v dd weak pull-up from other qd en qd en set rbif rb<7:4> pins v dd v ss q d q ck q d q ck q1 q3 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 43 pic16f627a/628a/648a figure 5-14: block diagram of rb6/t1oso/t1cki/pgc pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb schmitt trigger t1oscen data bus rb6/ tmr1 clock rbpu v dd weak pull-up p from rb7 t1oso/ t1cki/ pgc from other qd en set rbif rb<7:4> pins serial programming clock ttl input buffer tmr1 oscillator qd en v dd v ss q3 q1 pin downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 44 ? 2009 microchip technology inc. figure 5-15: block diagram of the rb7/t1osi/pgd pin data latch tris latch rd trisb q d q ck q d q ck rd portb wr portb wr trisb t10scen data bus rb7/t1osi/ to r b 6 rbpu v dd weak pull-up p pgd pin ttl input buffer from other qd en qd en set rbif rb<7:4> pins serial programming input schmitt trigger tmr1 oscillator v dd v ss q3 q1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 45 pic16f627a/628a/648a table 5-3: portb functions table 5-4: summary of regist ers associated with portb name function input type output type description rb0/int rb0 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. int st external interrupt rb1/rx/dt rb1 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. rx st usart receive pin dt st cmos synchronous data i/o rb2/tx/ck rb2 ttl cmos bidirectional i/o port tx cmos usart transmit pin ck st cmos synchronous clock i/o. can be software programmed for internal weak pull-up. rb3/ccp1 rb3 ttl cmos bidirectional i/o port. can be software programmed for internal weak pull-up. ccp1 st cmos capture/compare/pwm/i/o rb4/pgm rb4 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. pgm st low-voltage programming input pin. when low-voltage programming is enabled, the interrupt-on-pin change and weak pull-up resistor are disabled. rb5 rb5 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. rb6/t1oso/t1cki/ pgc rb6 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1oso xtal timer1 oscillator output t1cki st timer1 clock input pgc st icsp ? programming clock rb7/t1osi/pgd rb7 ttl cmos bidirectional i/o port. interrupt-on-pin change. can be software programmed for internal weak pull-up. t1osi xtal timer1 oscillator input pgd st cmos icsp data i/o legend: o = output cmos = cmos output p = power = not used i = input st = schmitt trigger input ttl = ttl input od = open drain output an = analog address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 06h, 106h portb rb7 rb6 rb5 rb4 (1) rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 86h, 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 81h, 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: u = unchanged, x = unknown. shaded cells are not used for portb. note 1: lvp configuration bit sets rb4 functionality. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 46 ? 2009 microchip technology inc. 5.3 i/o programming considerations 5.3.1 bidirectional i/o ports any instruction that writes operates internally as a read followed by a write operation. the bcf and bsf instructions, for example, read the register into the cpu, execute the bit operation and write the result back to the register. caution must be used when these instructions are applied to a port with both inputs and outputs defined. for example, a bsf operation on bit 5 of portb will cause all eight bits of portb to be read into the cpu. then the bsf operation takes place on bit 5 and portb is written to the output latches. if another bit of portb is used as a bidirectional i/o pin (e.g., bit 0) and is defined as an input at this time, the input signal present on the pin itself would be read into the cpu and rewritten to the data latch of this particular pin, overwriting the previous content. as long as the pin stays in the input mode, no problem occurs. however, if bit 0 is switched into output mode later on, the content of the data latch may now be unknown. reading a port register reads the values of the port pins. writing to the port register writes the value to the port latch. when using read-modify-write instructions (ex. bcf, bsf , etc.) on a port, the value of the port pins is read, the desired operation is done to this value, and this value is then written to the port latch. example 5-2 shows the effect of two sequential read- modify-write instructions (ex., bcf, bsf , etc.) on an i/o port. a pin actively outputting a low or high should not be driven from external devices at the same time in order to change the level on this pin (wired-or, wired- and). the resulting high output currents may damage the chip. example 5-2: read-modify-write instructions on an i/o port 5.3.2 successive operations on i/o ports the actual write to an i/o port happens at the end of an instruction cycle, whereas for reading, the data must be valid at the beginning of the instruction cycle (figure 5-16). therefore, care must be exercised if a write followed by a read operation is carried out on the same i/o port. the sequence of instructions should be such to allow the pin voltage to stabilize (load dependent) before the next instruction, which causes that file to be read into the cpu, is executed. other- wise, the previous state of that pin may be read into the cpu rather than the new state. when in doubt, it is better to separate these instructions with a nop or another instruction not accessing this i/o port. figure 5-16: successive i/o operation ;initial port settings:portb<7:4> inputs ; portb<3:0> outputs ;portb<7:6> have external pull-up and are ;not connected to other circuitry ; ; port latchport pins ---------- ---------- bcf status, rp0 ; bcf portb, 7 ;01pp pppp 11pp pppp bsf status, rp0 ; bcf trisb, 7 ;10pp pppp 11pp pppp bcf trisb, 6 ;10pp pppp 10pp pppp ; ;note that the user may have expected the ;pin values to be 00pp pppp. the 2nd bcf ;caused rb7 to be latched as the pin value ;(high). q1 q2 q3 q4 pc instruction fetched q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 pc + 1 pc pc + 2 pc + 3 movwf portb write to portb movf portb, w read to portb nop nop t pd execute movwf portb execute movf portb, w port pin sampled here execute nop note 1: this example shows write to portb followed by a read from portb. 2: data setup time = (0.25 t cy - t pd ) where t cy = instruction cycle and t pd = propagation delay of q1 cycle to output valid. therefore, at higher clock frequencies, a write followed by a read may be problematic. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 47 pic16f627a/628a/648a 6.0 timer0 module the timer0 module timer/counter has the following features: 8-bit timer/counter read/write capabilities 8-bit software programmable prescaler internal or external clock select interrupt on overflow from ffh to 00h edge select for external clock figure 6-1 is a simplified block diagram of the timer0 module. additional information is available in the ?pic ? mid-range mcu family reference manual? (ds33023). timer mode is selected by clearing the t0cs bit (option<5>). in timer mode, the tmr0 register value will increment every instruction cycle (without prescaler). if the tmr0 register is written to, the increment is inhibited for the following two cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting the t0cs bit. in this mode the tmr0 register value will increment either on every rising or falling edge of pin ra4/t0cki/cmp2. the incrementing edge is determined by the source edge (t0se) control bit (option<4>). clearing the t0se bit selects the rising edge. restrictions on the external clock input are discussed in detail in section 6.2 using timer0 with external clock . the prescaler is shared between the timer0 module and the watchdog timer. the prescaler assignment is controlled in software by the control bit psa (option<3>). clearing the psa bit will assign the prescaler to timer0. the prescaler is not readable or writable. when the prescaler is assigned to the timer0 module, prescale value of 1:2, 1:4,..., 1:256 are selectable. section 6.3 timer0 prescaler details the operation of the prescaler. 6.1 timer0 interrupt timer0 interrupt is generated when the tmr0 register timer/counter overflows from ffh to 00h. this overflow sets the t0if bit. the interrupt can be masked by clearing the t0ie bit (intcon<5>). the t0if bit (intcon<2>) must be cleared in software by the timer0 module interrupt service routine before re- enabling this interrupt. the timer0 interrupt cannot wake the processor from sleep since the timer is shut off during sleep. 6.2 using timer0 with external clock when an external clock input is used for timer0, it must meet certain requirements. the external clock requirement is due to internal phase clock (t osc ) synchronization. also, there is a delay in the actual incrementing of timer0 after synchronization. 6.2.1 external clock synchronization when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki with the internal phase clocks is accomplished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks (figure 6-1). therefore, it is necessary for t0cki to be high for at least 2t osc (and a small rc delay of 20 ns) and low for at least 2t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. when a prescaler is used, the external clock input is divided by the asynchronous ripple-counter type prescaler so that the prescaler output is symmetrical. for the external clock to meet the sampling requirement, the ripple-counter must be taken into account. therefore, it is necessary for t0cki to have a period of at least 4t osc (and a small rc delay of 40 ns) divided by the prescaler value. the only requirement on t0cki high and low time is that they do not violate the minimum pulse width requirement of 10 ns. refer to parameters 40, 41 and 42 in the electrical specification of the desired device. see table 17-8. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 48 ? 2009 microchip technology inc. 6.3 timer0 prescaler an 8-bit counter is available as a prescaler for the timer0 module, or as a postscaler for the watchdog timer. a prescaler assignment for the timer0 module means that there is no postscaler for the watchdog timer, and vice-versa. the psa and ps<2:0> bits (option<3:0>) determine the prescaler assignment and prescale ratio. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g., clrf 1, movwf 1, bsf 1, x....etc. ) will clear the prescaler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. the prescaler is not readable or writable. figure 6-1: block diagra m of the timer0/wdt t0cki t0se pin f osc /4 sync 2 cycles tmr0 reg 8-to-1mux watchdog timer psa wdt time-out ps<2:0> 8 . psa wdt enable bit data bus set flag bit t0if on overflow 8 psa note: t0se, t0cs, psa, ps<2:0> are bits in the option register. t0cs wdt postscaler/ tmr0 prescaler 10 1 0 1 0 10 tmr1 clock source downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 49 pic16f627a/628a/648a 6.3.1 switching prescaler assignment the prescaler assignment is fully under software control (i.e., it can be changed on-the-fly during program execution). use the instruction sequences shown in example 6-1 when changing the prescaler assignment from timer0 to wdt, to avoid an unintended device reset. example 6-1: changing prescaler (timer0 wdt) to change prescaler from the wdt to the timer0 module, use the sequence shown in example 6-2. this precaution must be taken even if the wdt is disabled. example 6-2: changing prescaler (wdt timer0) table 6-1: registers associated with timer0 bcf status, rp0 ;skip if already in ;bank 0 clrwdt ;clear wdt clrf tmr0 ;clear tmr0 and ;prescaler bsf status, rp0 ;bank 1 movlw '00101111?b ;these 3 lines ;(5, 6, 7) movwf option_reg ;are required only ;if desired ps<2:0>;are clrwdt ;000 or 001 movlw '00101xxx?b ;set postscaler to movwf option_reg ;desired wdt rate bcf status, rp0 ;return to bank 0 clrwdt ;clear wdt and ;prescaler bsf status, rp0 movlw b'xxxx0xxx? ;select tmr0, new ;prescale value and;clock source movwf option_regbcf status, rp0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 01h, 101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 81h, 181h option (2) rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: - = unimplemented locations, read as 0 , u = unchanged, x = unknown. shaded cells are not used for timer0. note 1: option is referred by option_reg in mplab ? ide software. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 50 ? 2009 microchip technology inc. 7.0 timer1 module the timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (tmr1h and tmr1l) which are readable and writable. the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow of the tmr1 register pair which latches the interrupt flag bit tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing the timer1 interrupt enable bit tmr1ie (pie1<0>). timer1 can operate in one of two modes: as a timer as a counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). in timer mode, the tmr1 register pair value increments every instruction cycle. in counter mode, it increments on every rising edge of the external clock input. timer1 can be enabled/disabled by setting/clearing control bit tmr1on (t1con<0>). timer1 also has an internal reset input. this reset can be generated by the ccp module ( section 9.0 capture/compare/pwm (ccp) module ). register 7-1 shows the timer1 control register. for the pic16f627a/628a/648a, when the timer1 oscillator is enabled (t1oscen is set), the rb7/ t1osi/pgd and rb6/t1oso/t1cki/pgc pins become inputs. that is, the trisb<7:6> value is ignored. register 7-1: t1con C timer1 control register (address: 10h) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7-6 unimplemented : read as 0 bit 5-4 t1ckps<1:0> : timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen : timer1 oscillator enable control bit 1 = oscillator is enabled 0 = oscillator is shut off (1) bit 2 t1sync : timer1 external clock input synchronization control bit tmr1cs = 1 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs = 0 this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs : timer1 clock source select bit 1 = external clock from pin rb6/t1oso/t1cki/pgc (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on : timer1 on bit 1 = enables timer1 0 = stops timer1 note 1: the oscillator inverter and feedback resistor are turned off to eliminate power drain. legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 51 pic16f627a/628a/648a 7.1 timer1 operation in timer mode timer mode is selected by clearing the tmr1cs (t1con<1>) bit. in this mode, the input clock to the timer is f osc /4. the synchronize control bit t1sync (t1con<2>) has no effect since the internal clock is always in sync. 7.2 timer1 operation in synchronized counter mode counter mode is selected by setting bit tmr1cs. in this mode, the tmr1 register pair value increments on every rising edge of clock input on pin rb7/t1osi/pgd when bit t1oscen is set or pin rb6/t1oso/t1cki/ pgc when bit t1oscen is cleared. if t1sync is cleared, then the external clock input is synchronized with internal phase clocks. the synchro- nization is done after the prescaler stage. the prescaler stage is an asynchronous ripple-counter. in this configuration, during sleep mode, the tmr1 register pair value will not increment even if the external clock is present, since the synchronization circuit is shut off. the prescaler however will continue to increment. 7.2.1 external clock input timing for synchronized counter mode when an external clock input is used for timer1 in synchronized counter mode, it must meet certain requirements. the external clock requirement is due to internal phase clock (t osc ) synchronization. also, there is a delay in the actual incrementing of the tmr1 register pair value after synchronization. when the prescaler is 1:1, the external clock input is the same as the prescaler output. the synchronization of t1cki with the internal phase clocks is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t1cki to be high for at least 2 t osc (and a small rc delay of 20 ns) and low for at least 2 t osc (and a small rc delay of 20 ns). refer to table 17-8 in the electrical specifications section, timing parameters 45, 46 and 47. when a prescaler other than 1:1 is used, the external clock input is divided by the asynchronous ripple-counter type prescaler so that the prescaler output is symmetri- cal. in order for the external clock to meet the sampling requirement, the ripple-counter must be taken into account. therefore, it is necessary for t1cki to have a period of at least 4 t osc (and a small rc delay of 40 ns) divided by the prescaler value. the only requirement on t1cki high and low time is that they do not violate the minimum pulse width requirements of 10 ns). refer to the appropriate electrical specifications in table 17-8, parameters 45, 46 and 47. figure 7-1: timer1 block diagram tmr1h tmr1l t1osc t1sync tmr1cs t1ckps<1:0> sleep input t1oscen enable oscillator (1) f osc /4 internal clock tmr1on prescaler 1, 2, 4, 8 synchronize det 10 01 synchronized clock input 2 rb6/t1oso/t1cki/pgc rb7/t1osi/pgd note 1: when the t1oscen bit is cleared, the inverter and feedback resistor are turned off. this eliminates power drain. set flag bit tmr1if on overflow tmr1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 52 ? 2009 microchip technology inc. 7.3 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt on overflow, which will wake-up the processor. however, special precautions in software are needed to read/write the timer ( section 7.3.2 reading and writing timer1 in asynchronous counter mode ). 7.3.1 external clock input timing with unsynchronized clock if control bit t1sync is set, the timer will increment completely asynchronously. the input clock must meet certain minimum high and low time requirements. refer to table 17-8 in the electrical specifications section, timing parameters 45, 46 and 47. 7.3.2 reading and writing timer1 in asynchronous counter mode reading the tmr1h or tmr1l register, while the timer is running from an external asynchronous clock, will produce a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself poses certain problems since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write contention may occur by writing to the timer registers while the register is incrementing. this may produce an unpredictable value in the timer register. reading the 16-bit value requires some care. example 7-1 is an example routine to read the 16-bit timer value. this is useful if the timer cannot be stopped. example 7-1: reading a 16-bit free- running timer note: in asynchronous counter mode, timer1 cannot be used as a time base for capture or compare operations. ; all interrupts are disabled movf tmr1h, w ;read high byte movwf tmph ; movf tmr1l, w ;read low byte movwf tmpl ; movf tmr1h, w ;read high byte subwf tmph, w ;sub 1st read with ;2nd read btfsc status,z ;is result = 0 goto continue ;good 16-bit read ; ; tmr1l may have rolled over between the ; read of the high and low bytes. reading ; the high and low bytes now will read a good ; value. ; movf tmr1h, w ;read high byte movwf tmph ; movf tmr1l, w ;read low byte movwf tmpl ; ; re-enable the interrupts (if required) continue ;continue with your ;code downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 53 pic16f627a/628a/648a 7.4 timer1 oscillator a crystal oscillator circuit is built in between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit t1oscen (t1con<3>). it will continue to run during sleep. it is primarily intended for a 32.768 khz watch crystal. table 7-1 shows the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper oscillator start-up. table 7-1: capacitor selection for the timer1 oscillator 7.5 resetting timer1 using a ccp trigger output if the ccp1 module is configured in compare mode to generate a special event trigger (ccp1m<3:0> = 1011 ), this signal will reset timer1. timer1 must be configured for either timer or synchronized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger from ccp1, the write will take precedence. in this mode of operation, the ccprxh:ccprxl register pair effectively becomes the period register for timer1. 7.6 resetting timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por or any other reset except by the ccp1 special event triggers (see section 9.2.4 special event trigger ). t1con register is reset to 00h on a power-on reset or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 7.7 timer1 prescaler the prescaler counter is cleared on writes to the tmr1h or tmr1l registers. table 7-2: registers associated with timer1 as a timer/counter freq c1 c2 32.768 khz 15 pf 15 pf note: these values are for design guidance only. consult application note an826 crystal oscillator basics and crystal selection for rfpic ? and pic ? devices? (ds00826) for further information on crystal/capacitor selection. note: the special event triggers from the ccp1 module will not set interrupt flag bit tmr1if (pir1<0>). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu legend: x = unknown, u = unchanged, - = unimplemented read as 0 . shaded cells are not used by the timer1 module. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 54 ? 2009 microchip technology inc. 8.0 timer2 module timer2 is an 8-bit timer with a prescaler and a postscaler. it can be used as the pwm time base for pwm mode of the ccp module. the tmr2 register is readable and writable, and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits t2ckps<1:0> (t2con<1:0>). the timer2 module has an 8-bit period register pr2. the tmr2 register value increments from 00h until it matches the pr2 register value and then resets to 00h on the next increment cycle. the pr2 register is a readable and writable register. the pr2 register is initialized to ffh upon reset. the match output of timer2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a timer2 interrupt (latched in flag bit tmr2if, (pir1<1>)). timer2 can be shut off by clearing control bit tmr2on (t2con<2>) to minimize power consumption. register 8-1 shows the timer2 control register. 8.1 timer2 prescaler and postscaler the prescaler and postscaler counters are cleared when any of the following occurs: a write to the tmr2 register a write to the t2con register any device reset (power-on reset, mclr reset, watchdog timer reset or brown-out reset) the tmr2 register is not cleared when t2con is written. 8.2 tmr2 output the tmr2 output (before the postscaler) is fed to the synchronous serial port module which optionally uses it to generate shift clock. figure 8-1: timer2 block diagram comparator tmr2 sets flag tmr2 reg output reset postscaler prescaler pr2 reg 2 f osc /4 1:1 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if to t2ckps<1:0> toutps<3:0> downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 55 pic16f627a/628a/648a register 8-1: t2con C timer2 control register (address: 12h) table 8-1: registers associated with timer2 as a timer/counter u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 toutps3 toutps2 toutps1 to utps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented : read as 0 bit 6-3 toutps<3:0> : timer2 output postscale select bits 0000 = 1:1 postscale value 0001 = 1:2 postscale value 1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0> : timer2 clock prescale select bits 00 = 1:1 prescaler value 01 = 1:4 prescaler value 1x = 1:16 prescaler value legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 11h tmr2 timer2 modules register 0000 0000 0000 0000 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented read as 0 . shaded cells are not used by the timer2 module. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 56 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 57 pic16f627a/628a/648a 9.0 capture/compare/pwm (ccp) module the ccp (capture/compare/pwm) module contains a 16-bit register which can operate as a 16-bit capture register, as a 16-bit compare register or as a pwm master/slave duty cycle register. table 9-1 shows the timer resources of the ccp module modes. ccp1 module capture/compare/pwm register1 (ccpr1) is comprised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. all are readable and writable. additional information on the ccp module is available in the pic ? mid-range mcu family reference man- ual? (ds33023). table 9-1: ccp mode C timer resource register 9-1: ccp1con C ccp ope ration register (address: 17h) ccp mode timer resource capture timer1 compare timer1 pwm timer2 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented : read as 0 bit 5-4 ccp1x:ccp1y : pwm least significant bits capture mode unused compare mode unused pwm mode these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccprxl. bit 3-0 ccp1m<3:0> : ccpx mode select bits 0000 = capture/compare/pwm off (resets ccp1 module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit is set; ccp1 resets tmr1 11xx = pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 58 ? 2009 microchip technology inc. 9.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin rb3/ccp1. an event is defined as: every falling edge every rising edge every 4th rising edge every 16th rising edge an event is selected by control bits ccp1m<3:0> (ccp1con<3:0>). when a capture is made, the interrupt request flag bit ccp1if (pir1<2>) is set. it must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value will be lost. 9.1.1 ccp pin configuration in capture mode, the rb3/ccp1 pin should be config- ured as an input by setting the trisb<3> bit. figure 9-1: capture mode operation block diagram 9.1.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 9.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit ccp1if following any such change in operating mode. 9.1.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m<3:0>. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore the fi rst capture may be from a non-zero prescaler. example 9-1 shows the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the false interrupt. example 9-1: changing between capture prescalers 9.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the rb3/ccp1 pin is: driven high driven low remains unchanged the action on the pin is based on the value of control bits ccp1m<3:0> (ccp1con<3:0>). at the same time, interrupt flag bit ccp1if is set. figure 9-2: compare mode operation block diagram note: if the rb3/ccp1 is configured as an output, a write to the port can cause a capture condition. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> rb3/ccp1 prescaler 3 1, 4, 16 and edge detect pin clrf ccp1con ;turn ccp module off movlw new_capt_ps ;load the w reg with ; the new prescaler; mode value and ccp on movwf ccp1con ;load ccp1con with this ; value ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic set flag bit ccp1if (pir1<2>) match rb3/ccp1 trisb<3> ccp1con<3:0> mode select output enable pin note: special event trigger will reset timer1, but not set interrupt flag bit tmr1if (pir1<0>). downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 59 pic16f627a/628a/648a 9.2.1 ccp pin configuration the user must configure the rb3/ccp1 pin as an output by clearing the trisb<3> bit. 9.2.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 9.2.3 software interrupt mode when generate software interrupt is chosen the ccp1 pin is not affected. only a ccp interrupt is generated (if enabled). 9.2.4 special event trigger in this mode (ccp1m<3:0>=1011), an internal hard- ware trigger is generated, which may be used to initiate an action. see register 9-1. the special event trigger output of the ccp occurs immediately upon a match between the tmr1h, tmr1l register pair and ccpr1h, ccpr1l register pair. the tmr1h, tmr1l register pair is not reset until the next rising edge of the tmr1 clock. this allows the ccpr1 register pair to effectively be a 16-bit program- mable period register for timer1. the special event trigger output also starts an a/d conversion provided that the a/d module is enabled. table 9-2: registers associated with capture, compare, and timer1 note: clearing the ccp1con register will force the rb3/ccp1 compare output latch to the default low level. this is not the data latch. note: removing the match condition by chang- ing the contents of the ccpr1h, ccpr1l register pair between the clock edge that generates the special event trigger and the clock edge that generates the tmr1 reset will preclude the reset from occuring. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 86h, 186h trisb portb data direction register 1111 1111 1111 1111 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented read as 0 . shaded cells are not used by capture and timer1. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 60 ? 2009 microchip technology inc. 9.3 pwm mode in pulse width modulation (pwm) mode, the ccp1 pin produces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with the portb data latch, the trisb<3> bit must be cleared to make the ccp1 pin an output. figure 9-3 shows a simplified block diagram of the ccp module in pwm mode. for a step by step procedure on how to set up the ccp module for pwm operation, see section 9.3.3 set- up for pwm operation . figure 9-3: simplified pwm block diagram a pwm output (figure 9-4) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (frequency = 1/period). figure 9-4: pwm output 9.3.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: tmr2 is cleared the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set) the pwm duty cycle is latched from ccpr1l into ccpr1h note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portb i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisb<3> rb3/ccp1 note 1: 8-bit timer is concatenated with 2-bit internal q clock or 2 bits of the prescaler to create 10-bit time base. note: the timer2 postscaler (see section 8.0 timer2 module ) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period pr 2 () 1 + [] 4 ?? = tosc tmr2 prescale ? value downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 61 pic16f627a/628a/648a 9.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available: the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time: ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read-only register. the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitchless pwm operation. when the ccpr1h and 2-bit latch match tmr2 concatenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. maximum pwm resolution (bits) for a given pwm frequency: for an example pwm period and duty cycle calculation, see the pic ? mid-range reference man- ual (ds33023). 9.3.3 set-up for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the trisb<3> bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. table 9-3: example pwm frequencies and resolutions at 20 mhz table 9-4: registers associated with pwm and timer2 (ccpr1l:ccp1con<5:4>) tosc tmr2 prescale ?? value pwm duty cycle = note: if the pwm duty cycle value is longer than the pwm period the ccp1 pin will not be cleared. resolution log fosc f pwm tmr2 prescaler ------------------------------------------------------------- ?? ?? log(2) --------------------------------------------------------------------------- b i t s = pwm pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12 khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xff 0xff 0xff 0x3f 0x1f 0x17 maximum resolution (bits) 10 10 10 8 7 6.5 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 86h, 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 11h tmr2 timer2 modules register 0000 0000 0000 0000 92h pr2 timer2 modules period register 1111 1111 1111 1111 12h t2con toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 uuuu uuuu 15h ccpr1l capture/compare/pwm register 1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register 1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented read as 0 . shaded cells are not used by pwm and timer2. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 62 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 63 pic16f627a/628a/648a 10.0 comparator module the comparator module contains two analog comparators. the inputs to the comparators are multiplexed with the ra0 through ra3 pins. the on-chip voltage reference ( section 11.0 voltage reference module ) can also be an input to the comparators. the cmcon register, shown in register 10-1, controls the comparator input and output multiplexers. a block diagram of the comparator is shown in figure 10-1. register 10-1: cmcon C comp arator configuration regist er (address: 01fh) r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 c2out c1out c2inv c1inv cis cm2 cm1 cm0 bit 7 bit 0 bit 7 c2out : comparator 2 output bit when c2inv = 0 : 1 = c2 v in + > c2 v in - 0 = c2 v in + < c2 v in - when c2inv = 1 : 1 = c2 v in + < c2 v in - 0 = c2 v in + > c2 v in - bit 6 c1out : comparator 1 output bit when c1inv = 0 : 1 = c1 v in + > c1 v in - 0 = c1 v in + < c1 v in - when c1inv = 1 : 1 = c1 v in + < c1 v in - 0 = c1 v in + > c1 v in - bit 5 c2inv : comparator 2 output inversion bit 1 = c2 output inverted 0 = c2 output not inverted bit 4 c1inv : comparator 1 output inversion bit 1 = c1 output inverted 0 = c1 output not inverted bit 3 cis : comparator input switch bit when cm<2:0>: = 001 then: 1 = c1 v in - connects to ra3 0 = c1 v in - connects to ra0 when cm<2:0> = 010 then: 1 = c1 v in - connects to ra3 c2 v in - connects to ra2 0 = c1 v in - connects to ra0 c2 v in - connects to ra1 bit 2-0 cm<2:0> : comparator mode bits figure 10-1 shows the comparator modes and cm<2:0> bit settings legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 64 ? 2009 microchip technology inc. 10.1 comparator configuration there are eight modes of operation for the comparators. the cmcon register is used to select the mode. figure 10-1 shows the eight possible modes. the trisa register controls the data direction of the comparator pins for each mode. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in table 17-2. figure 10-1: comparator i/o operating modes note 1: comparator interrupts should be disabled during a comparator mode change, otherwise a false interrupt may occur. 2: comparators can have an inverted output. see figure 10-1. c1 ra0/an0 v in - v in + ra3/an3/cmp1 comparators reset (por default value) aa cm<2:0> = 000 c2 ra1/an1 v in - v in + ra2/an2/v ref aa c1 ra0/an0 v in - v in + ra3/an3/cmp1 two independent comparators aa cm<2:0> = 100 c2 ra1/an1 v in - v in + ra2/an2/v ref aa c1 ra0/an0 v in - v in + ra3/an3/cmp1 two common reference comparators ad cm<2:0> = 011 c2 ra1/an1 v in - v in + ra2/an2/v ref aa c1 ra0/an0 v in - v in + ra3/an3/cmp1 off (read as 0 ) one independent comparator dd cm<2:0> = 101 c2 ra1/an1 v in - v in + ra2/an2/v ref aa c1 v in - v in + off (read as 0 ) comparators off dd cm<2:0> = 111 c2 v in - v in + off (read as 0 ) dd c1 ra0/an0 v in - v in + ra3/an3/cmp1 four inputs multiplexed to two comparators aa cm<2:0> = 010 c2 ra1/an1 v in - v in + ra2/an2/v ref aa from v ref cis = 0 cis = 1 cis = 0 cis = 1 c1 ra0/an0 v in - v in + ra3/an3/cmp1 two common reference comparators with outputs ad cm<2:0> = 110 c2 ra1/an1 v in - v in + ra2/an2/v ref aa open drain a = analog input, port reads zeros always. d = digital input. cis (cmcon<3>) is the comparator input switch. ra4/t0cki/cmp2 c1 ra0/an0 v in - v in + ra3/an3/cmp1 three inputs multiplexed to two comparators aa cm<2:0> = 001 c2 ra1/an1 v in - v in + ra2/an2/v ref aa cis = 0 cis = 1 v ss v ss ra0/an0 ra3/an3/cmp1 ra1/an1 ra2/an2/v ref module c1v out c2v out c1v out c2v out off (read as 0 ) off (read as 0 ) c2v out c1v out c2v out c1v out c2v out c1v out c2v out downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 65 pic16f627a/628a/648a the code example in example 10-1 depicts the steps required to configure the comparator module. ra3 and ra4 are configured as digital output. ra0 and ra1 are configured as the v- inputs and ra2 as the v+ input to both comparators. example 10-1: initializing comparator module 10.2 comparator operation a single comparator is shown in figure 10-2 along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input v in -, the output of the comparator is a digital low level. when the analog input at v in + is greater than the analog input v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 10-2 represent the uncertainty due to input offsets and response time. see table 17-2 for common mode voltage. 10.3 comparator reference an external or internal reference signal may be used depending on the comparator operating mode. the analog signal that is present at v in - is compared to the signal at v in +, and the digital output of the comparator is adjusted accordingly (figure 10-2). figure 10-2: single comparator 10.3.1 external reference signal when external voltage references are used, the comparator module can be configured to have the comparators operate from the same or different reference sources. however, threshold detector applications may require the same reference. the reference signal must be between v ss and v dd , and can be applied to either pin of the comparator(s). 10.3.2 internal reference signal the comparator module also allows the selection of an internally generated voltage reference for the comparators. section 11.0 voltage reference module , contains a detailed description of the voltage reference module that provides this signal. the internal reference signal is used when the comparators are in mode cm<2:0> = 010 (figure 10-1). in this mode, the internal voltage reference is applied to the v in + pin of both comparators. 10.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output is to have a valid level. if the internal reference is changed, the maximum delay of the internal voltage reference must be considered when using the comparator outputs. otherwi se, the maximum delay of the comparators should be used (table 17-2, page 142) . flag_reg equ 0x20 clrf flag_reg ;init flag register clrf porta ;init porta movf cmcon, w ;load comparator bits andlw 0xc0 ;mask comparator bits iorwf flag_reg,f ;store bits in flag register movlw 0x03 ;init comparator mode movwf cmcon ;cm<2:0> = 011 bsf status,rp0 ;select bank1 movlw 0x07 ;initialize data direction movwf trisa ;set ra<2:0> as inputs ;ra<4:3> as outputs ;trisa<7:5> always read ?0? bcf status,rp0 ;select bank 0 call delay10 ;10 s delay movf cmcon,f ;rea d cmco n to end change ;condition bcf pir1,cmif ;clear pending interrupts bsf status,rp0 ;select bank 1 bsf pie1,cmie ;enable comparator interrupts bcf status,rp0 ;select bank 0 bsf intcon,peie ;enable peripheral interrupts bsf intcon,gie ;global interrupt enable C + v in + v in - result result v in - v in + downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 66 ? 2009 microchip technology inc. 10.5 comparator outputs the comparator outputs are read through the cmcon register. these bits are read-only. the comparator outputs may also be directly output to the ra3 and ra4 i/o pins. when the cm<2:0> = 110 or 001 , multiplexors in the output path of the ra3 and ra4/t0ck1/cmp2 pins will switch and the output of each pin will be the unsynchronized output of the comparator. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. figure 10-3 shows the comparator output block diagram. the trisa bits will still function as an output enable/ disable for the ra3/an3/cmp1 and ra4/t0ck1/ cmp2 pins while in this mode. figure 10-3: modified comp arator output block diagram note 1: when reading the port register, all pins configured as analog inputs will read as a 0 . pins configured as digital inputs will convert an analog input, according to the schmitt trigger input specification. 2: analog levels on any pin that is defined as a digital input may cause the input buffer to consume more current than is specified. d q en to ra3/an3/cmp1 or set cmif bit d q en cl reset from other comparator to d a ta b u s cnv out cni nv q1 rd cmcon cmcon<7:6> q3 ra4/t0ck1/cmp2 pin downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 67 pic16f627a/628a/648a 10.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:6>, to determine the actual change that has occurred. the cmif bit, pir1<6>, is the comparator interrupt flag. the cmif bit must be reset by clearing 0 . since it is also possible to write a 1 to this register, a simulated interrupt may be initiated. the cmie bit (pie1<6>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any write or read of cmcon. this will end the mismatch condition. b) clear flag bit cmif. a mismatch condition will continue to set flag bit cmif. reading cmcon will end the mismatch condition and allow flag bit cmif to be cleared. 10.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode when enabled. while the comparator is powered-up, higher sleep currents than shown in the power-down current specification will occur. each comparator that is operational will consume additional current as shown in the comparator specifications. to minimize power consumption while in sleep mode, turn off the comparators, cm<2:0> = 111 , before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 10.8 effects of a reset a device reset forces the cmcon register to its reset state. this forces the comparator module to be in the comparator reset mode, cm<2:0> = 000 . this ensures that all potential inputs are analog inputs. device current is minimized when analog inputs are present at reset time. the comparators will be powered-down during the reset interval. 10.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 10-4. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up may occur. a maximum source impedance of 10 k is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. note: if a change in the cmcon register (c1out or c2out) should occur when a read operation is being executed (start of the q2 cycle), then the cmif (pir1<6>) interrupt flag may not get set. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 68 ? 2009 microchip technology inc. figure 10-4: analog input mode table 10-1: registers associated with comparator module address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 1fh cmcon c2out c1out c2inv c1nv cis cm2 cm1 cm0 0000 0000 0000 0000 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as 0 va r s < 10 k a in c pin 5pf v dd v t = 0.6v v t = 0.6v r ic i leakage 500 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin r ic = interconnect resistance r s = source impedance va = analog voltage downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 69 pic16f627a/628a/648a 11.0 voltage reference module the voltage reference module consists of a 16-tap resistor ladder network that provides a selectable volt- age reference. the resistor ladder is segmented to pro- vide two ranges of v ref values and has a power-down function to conserve power when the reference is not being used. the vrcon register controls the opera- tion of the reference as shown in figure 11-1. the block diagram is given in figure 11-1. 11.1 voltage reference configuration the voltage reference module can output 16 distinct voltage levels for each range. the equations used to calculate the output of the voltage reference module are as follows: if vrr = 1 : if vrr = 0 : the setting time of the voltage reference module must be considered when changing the v ref output (table 17-3). example 11-1 demonstrates how voltage reference is configured for an output voltage of 1.25v with v dd = 5.0v. register 11-1: vrcon C voltage referenc e control register (address: 9fh) v ref v r <3:0> 24 ---------------------- -v dd = v ref v dd 14 -- - ?? ?? v r <3:0> 32 ---------------------- - +v dd = r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 vren vroe vrr vr3 vr2 vr1 vr0 bit 7 bit 0 bit 7 vren : v ref enable bit 1 = v ref circuit powered on 0 = v ref circuit powered down, no i dd drain bit 6 vroe : v ref output enable bit 1 = v ref is output on ra2 pin 0 = v ref is disconnected from ra2 pin bit 5 vrr : v ref range selection bit 1 = low range 0 = high range bit 4 unimplemented : read as 0 bit 3-0 vr<3:0> : v ref value selection bits 0 vr <3:0> 15 when vrr = 1 : v ref = (vr<3:0>/ 24) * v dd when vrr = 0 : v ref = 1/4 * v dd + (vr<3:0>/ 32) * v dd legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 70 ? 2009 microchip technology inc. figure 11-1: voltage reference block diagram example 11-1: voltage reference configuration 11.2 voltage reference accuracy/error the full range of v ss to v dd cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 11-1) keep v ref from approaching v ss or v dd . the voltage reference module is v dd derived and therefore, the v ref output changes with fluctuations in v dd . the tested absolute accuracy of the voltage ref- erence module can be found in table 17-3. 11.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time out, the contents of the vrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference module should be disabled. 11.4 effects of a reset a device reset disables the voltage reference module by clearing bit vren (vrcon<7>). this reset also disconnects the reference from the ra2 pin by clearing bit vroe (vrcon<6>) and selects the high voltage range by clearing bit vrr (vrcon<5>). the v ref value select bits, vrcon<3:0>, are also cleared. 11.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra2 pin if the trisa<2> bit is set and the vroe bit, vrcon<6>, is set. enabling the voltage reference module output onto the ra2 pin with an input signal present will increase current consumption. connecting ra2 as a digital output with v ref enabled will also increase current consump- tion. the ra2 pin can be used as a simple d/a output with limited drive capability. due to the limited drive capability, a buffer must be used in conjunction with the voltage reference module output for external connec- tions to v ref . figure 11-2 shows an example buffering technique. note: r is defined in table 17-3. vrr 8r v r 3 v r 0 (from vrcon<3:0>) 16-1 analog mux 8r r r r r vren v ref 16 stages v dd v ss v ss movlw 0x02 ;4 inputs muxed movwf cmcon ;to 2 comps. bsf status,rp0 ;go to bank 1 movlw 0x07 ;ra3-ra0 are movwf trisa ;outputs movlw 0xa6 ;enable v ref movwf vrcon ;low range set v r <3:0>=6 bcf status,rp0 ;go to bank 0 call delay10 ;10 s delay downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 71 pic16f627a/628a/648a figure 11-2: voltage refere nce output buffer example table 11-1: registers associated with voltage reference address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 9fh vrcon vren vroe vrr vr3 vr2 vr1 vr0 000- 0000 000- 0000 1fh cmcon c2out c1out c2inv c1inv cis cm2 cm1 cm0 0000 0000 0000 0000 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: - = unimplemented, read as 0 . note 1: r is dependent upon the voltage reference configuration vrcon<3:0> and vrcon<5>. v ref module r (1) voltage reference output impedance ra2 v ref output + op amp downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 72 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 73 pic16f627a/628a/648a 12.0 universal synchronous asynchronous receiver transmitter (usart) module the universal synchronous asynchronous receiver transmitter (usart) is also known as a serial communications interface (sci). the usart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices such as crt terminals and personal computers, or it can be configured as a half-duplex synchronous system that can communicate with peripheral devices such as a/d or d/a integrated circuits, serial eeproms, etc. the usart can be configured in the following modes: asynchronous (full-duplex) synchronous C master (half-duplex) synchronous C slave (half-duplex) bit spen (rcsta<7>) and bits trisb<2:1> have to be set in order to configure pins rb2/tx/ck and rb1/rx/dt as the universal synchronous asynchronous receiver transmitter. register 12-1 shows the transmit status and control register (txsta) and register 12-2 shows the receive status and control register (rcsta). register 12-1: txsta C transmit stat us and control register (address: 98h) r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r-1 r/w-0 csrc tx9 txen sync brgh trmt tx9d bit 7 bit 0 bit 7 csrc : clock source select bit asynchronous mode dont care synchronous mode 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9 : 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen : transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync : usart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 unimplemented : read as 0 bit 2 brgh : high baud rate select bit asynchronous mode 1 = high speed 0 = low speed synchronous mode unused in this mode bit 1 trmt : transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d : 9th bit of transmit data. can be parity bit. note 1: sren/cren overrides txen in sync mode. legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 74 ? 2009 microchip technology inc. register 12-2: rcsta C receive status and control re gister (address: 18h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren aden ferr oerr rx9d bit 7 bit 0 bit 7 spen : serial port enable bit (configures rb1/rx/dt and rb2/tx/ck pins as serial port pins when bits trisb<2:1> are set) 1 = serial port enabled 0 = serial port disabled bit 6 rx9 : 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren : single receive enable bit asynchronous mode : dont care synchronous mode - master : 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode - slave : unused in this mode bit 4 cren : continuous receive enable bit asynchronous mode : 1 = enables continuous receive 0 = disables continuous receive synchronous mode : 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 aden : address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enable interrupt and load of the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received, and ninth bit can be used as parity bit asynchronous mode 8-bit (rx9 = 0 ) : unused in this mode synchronous mode unused in this mode bit 2 ferr : framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr : overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d : 9th bit of received data (can be parity bit) legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 75 pic16f627a/628a/648a 12.1 usart baud rate generator (brg) the brg supports both the asynchronous and synchronous modes of the usart. it is a dedicated 8-bit baud rate generator. the spbrg register controls the period of a free running 8-bit timer. in asynchronous mode, bit brgh (txsta<2>) also controls the baud rate. in synchronous mode, bit brgh is ignored. table 12-1 shows the formula for computation of the baud rate for different usart modes, which only apply in master mode (internal clock). given the desired baud rate and f osc , the nearest integer value for the spbrg register can be calculated using the formula in table 12-1. from this, the error in baud rate can be determined. example 12-1 shows the calculation of the baud rate error for the following conditions: f osc = 16 mhz desired baud rate = 9600 brgh = 0 sync = 0 equation 12-1: calculating baud rate error it may be advantageous to use the high baud rate (brgh = 1 ) even for slower baud clocks. this is because the f osc /(16(x + 1)) equation can reduce the baud rate error in some cases. writing a new value to the spbrg register causes the brg timer to be reset (or cleared) and ensures the brg does not wait for a timer overflow before outputting the new baud rate. the data on the rb1/rx/dt pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 12-1: baud rate formula table 12-2: registers associated with baud rate generator desired baud rate fosc 64 x 1 + () ----------------------- = 9600 16000000 64 x 1 + () ----------------------- - = x25.042 = calculated baud rate 16000000 64 25 1 + () -------------------------- -9615 == error (calculated baud rate - desired baud rate) desired baud rate ---------------------------------------------------------------------------------------------------------- - = = 9615 9600 ? 9600 ----------------------------- -0.16% = sync brgh = 0 (low speed) brgh = 1 (high speed) 0 (asynchronous) baud rate = f osc /(64(x+1)) baud rate = f osc /(16(x+1)) 1 (synchronous) baud rate = f osc /(4(x+1)) na legend: x = value in spbrg (0 to 255) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 98h txsta csrc tx9 txen sync b r g h trmt tx9d 0000 -010 0000 -010 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as 0 . shaded cells are not used for the brg. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 76 ? 2009 microchip technology inc. table 12-3: baud rates for synchronous mode baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0 . 3n a n a n a 1 . 2n a n a n a 2 . 4n a n a n a 9.6 na na 9.766 +1.73% 255 19.2 19.53 +1.73% 255 19.23 +0.16% 207 19.23 +0.16% 129 76.8 76.92 +0.16% 64 76.92 +0.16% 51 75.76 -1.36% 32 96 96.15 +0.16% 51 95.24 -0.79% 41 96.15 +0.16% 25 300 294.1 -1.96 16 307.69 +2.56% 12 312.5 +4.17% 7 500 500 0 9 500 0 7 500 0 4 high 5000 0 4000 0 2500 0 low 19.53 255 15.625 255 9.766 255 baud rate (k) f osc = 7.15909 mhz spbrg value (decimal) 5.0688 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0 . 3n a n a n a 1 . 2n a n a n a 2 . 4n a n a n a 9.6 9.622 +0.23% 185 9.6 0 131 9.615 +0.16% 103 19.2 19.24 +0.23% 92 19.2 0 65 19.231 +0.16% 51 76.8 77.82 +1.32 22 79.2 +3.13% 15 75.923 +0.16% 12 96 94.20 -1.88 18 97.48 +1.54% 12 1000 +4.17% 9 300 298.3 -0.57 5 316.8 5.60% 3 na 500 na na n a high 1789.8 0 1267 0 100 0 low 6.991 255 4.950 255 3.906 255 baud rate (k) f osc = 3.579545 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 na na 0.303 +1.14% 26 1.2 na 1.202 +0.16% 207 1.170 -2.48% 6 2.4 na 2.404 +0.16% 103 na 9.6 9.622 +0.23% 92 9.615 +0.16% 25 na 19.2 19.04 -0.83% 46 19.24 +0.16% 12 na 76.8 74.57 -2.90% 11 83.34 +8.51% 2 na 96 99.43 +3.57% 8 na na 300 298.3 0.57% 2 na na 500 na n a n a high 894.9 0 250 0 8.192 0 low 3.496 255 0.9766 255 0.032 255 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 77 pic16f627a/628a/648a table 12-4: baud rates for as ynchronous mode (brgh = 0 ) baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0 . 3n an a n a 1.2 1.221 +1.73% 255 1.202 +0.16% 207 1.202 +0.16% 129 2.4 2.404 +0.16% 129 2.404 +0.16% 103 2.404 +0.16% 64 9.6 9.469 -1.36% 32 9.615 +0.16% 25 9.766 +1.73% 15 19.2 19.53 +1.73% 15 19.23 +0.16% 12 19.53 +1.73v 7 76.8 78.13 +1.73% 3 83.33 +8.51% 2 78.13 +1.73% 1 96 104.2 +8.51% 2 na na 300 312.5 +4.17% 0 na na 500 na na na high 312.5 0 250 0 156.3 0 low 1.221 255 0.977 255 0.6104 255 baud rate (k) f osc = 7.15909 mhz spbrg value (decimal) 5.0688 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 na 0.31 +3.13% 255 0.3005 -0.17% 207 1.2 1.203 +0.23% 92 1.2 0 65 1.202 +1.67% 51 2.4 2.380 -0.83% 46 2.4 0 32 2.404 +1.67% 25 9.6 9.322 -2.90% 11 9.9 +3.13% 7 na 19.2 18.64 -2.90% 5 19.8 +3.13% 3 na 76.8 na 79.2 +3.13% 0 na 96 na na na 300 na na na 500 na na na high 111.9 0 79.2 0 62.500 0 low 0.437 255 0.3094 255 3.906 255 baud rate (k) f osc = 3.579545 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 0.3 0.301 +0.23% 185 0.300 +0.16% 51 0.256 -14.67% 1 1.2 1.190 -0.83% 46 1.202 +0.16% 12 na 2.4 2.432 +1.32% 22 2.232 -6.99% 6 na 9.6 9.322 -2.90% 5 na na 19.2 18.64 -2.90% 2 na na 7 6 . 8n a n a n a 96 na na na 300 na na na 500 na na na high 55.93 0 15.63 0 0.512 0 low 0.2185 255 0.0610 255 0.0020 255 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 78 ? 2009 microchip technology inc. table 12-5: baud rates for asynchronous mode (brgh = 1 ) baud rate (k) f osc = 20 mhz spbrg value (decimal) 16 mhz spbrg value (decimal) 10 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9.615 +0.16% 129 9.615 +0.16% 103 9.615 +0.16% 64 19200 19.230 +0.16% 64 19.230 +0.16% 51 18.939 -1.36% 32 38400 37.878 -1.36% 32 38.461 +0.16% 25 39.062 +1.7% 15 57600 56.818 -1.36% 21 58.823 +2.12% 16 56.818 -1.36% 10 115200 113.636 -1.36% 10 111.111 -3.55% 8 125 +8.51% 4 250000 250 0 4 250 0 3 na 625000 625 0 1 na 625 0 0 1250000 1250 0 0 na na baud rate (k) f osc = 7.16 mhz spbrg value (decimal) 5.068 mhz spbrg value (decimal) 4 mhz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9.520 -0.83% 46 9598.485 0.016% 32 9615.385 0.160% 25 19200 19.454 +1.32% 22 18632.35 -2.956% 16 19230.77 0.160% 12 38400 37.286 -2.90% 11 39593.75 3.109% 7 35714.29 -6.994% 6 57600 55.930 -2.90% 7 52791.67 -8.348% 5 62500 8.507% 3 115200 111.860 -2.90% 3 105583.3 -8.348% 2 125000 8.507% 1 250000 na 316750 26.700% 0 250000 0.000% 0 625000 na na na 1250000 na na na baud rate (k) f osc = 3.579 mhz spbrg value (decimal) 1 mhz spbrg value (decimal) 32.768 khz spbrg value (decimal) kbaud error kbaud error kbaud error 9600 9725.543 1.308% 22 8.928 -6.994% 6 na na na 19200 18640.63 -2.913% 11 20833.3 8.507% 2 na na na 38400 37281.25 -2.913% 5 31250 -18.620% 1 na na na 57600 55921.88 -2.913% 3 62500 +8.507 0 na na na 115200 111243.8 -2.913% 1 na na na na 250000 223687.5 -10.525% 0 na na na na 625000 na na na na na 1250000 na na na na na downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 79 pic16f627a/628a/648a 12.2 usart asynchronous mode in this mode, the usart uses standard non-return-to- zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8-bit. a dedicated 8-bit baud rate generator is used to derive baud rate frequencies from the oscillator. the usart transmits and receives the lsb first. the usarts transmitter and receiver are functionally independent, but use the same data format and baud rate. the baud rate generator produces a clock either x16 or x64 of the bit shift rate, depending on bit brgh (txsta<2>). parity is not supported by the hardware, but can be implemented in software (and stored as the ninth data bit). asynchronous mode is stopped during sleep. asynchronous mode is selected by clearing bit sync (txsta<4>). the usart asynchronous module consists of the following important elements: baud rate generator sampling circuit asynchronous transmitter asynchronous receiver 12.2.1 usart asynchronous transmitter the usart transmitter block diagram is shown in figure 12-1. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and flag bit txif (pir1<4>) is set. this interrupt can be enabled/ disabled by setting/clearing enable bit txie ( pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicated the status of the txreg register, another bit trmt (txsta<1>) shows the status of the tsr register. status bit trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data and the baud rate generator (brg) has produced a shift clock (figure 12-1). the transmission can also be started by first loading the txreg register and then setting enable bit txen. normally when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr resulting in an empty txreg. a back- to-back transfer is thus possible (figure 12-3). clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. as a result the rb2/tx/ck pin will revert to high-impedance. in order to select 9-bit transmission, transmit bit tx9 (txsta<6>) should be set and the ninth bit should be written to tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg register can result in an immediate transfer of the data to the tsr register (if the tsr is empty). in such a case, an incorrect ninth data bit may be loaded in the tsr register. note 1: the tsr register is not mapped in data memory so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 80 ? 2009 microchip technology inc. figure 12-1: usart transmit block diagram follow these steps when setting up an asynchronous transmission: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. ( section 12.1 usart baud rate generator (brg) ). 3. enable the asynchronous serial port by clearing bit sync and setting bit spen. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set transmit bit tx9. 6. enable the transmission by setting bit txen, which will also set bit txif. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. load data to the txreg register (starts transmission). figure 12-2: asynchronous transmission txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen rb2/tx/ck pin pin buffer and control 8 2 2 2 word 1 stop bit word 1 transmit shift reg. start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rb2/tx/ck (pin) txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 81 pic16f627a/628a/648a figure 12-3: asynchronous transmission (back to back) table 12-6: registers associated with asynchronous transmission address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as 0 . shaded cells are not used for asynchronous transmission. transmit shift reg. write to txreg brg output (shift clock) rb2/tx/ck (pin) txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 . note: this timing diagram shows two consecutive transmissions. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 82 ? 2009 microchip technology inc. 12.2.2 usart asynchronous receiver the receiver block diagram is shown in figure 12-4. the data is received on the rb1/rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . when asynchronous mode is selected, reception is enabled by setting bit cren (rcsta<4>). the heart of the receiver is the receive (serial) shift register (rsr). after sampling the stop bit, the received data in the rsr is transferred to the rcreg register (if it is empty). if the transfer is complete, flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read-only bit, which is cleared by the hardware. it is cleared when the rcreg register has been read and is empty. the rcreg is a double buffered register (i.e., it is a two-deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte begin shifting to the rsr register. on the detection of the stop bit of the third byte, if the rcreg register is still full, then overrun error bit oerr (rcsta<1>) will be set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. overrun bit oerr has to be cleared in soft- ware. this is done by resetting the receive logic (cren is cleared and then set). if bit oerr is set, transfers from the rsr register to the rcreg register are inhib- ited, so it is essential to clear error bit oerr if it is set. framing error bit ferr (rcsta<2>) is set if a stop bit is detected as clear. bit ferr and the 9th receive bit are buffered the same way as the receive data. read- ing the rcreg, will load bits rx9d and ferr with new values, therefore it is essential for the user to read the rcsta register before reading rcreg register in order not to lose the old ferr and rx9d information. figure 12-4: usart receive block diagram x64 baud rate clk spbrg baud rate generator rb1/rx/dt pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? rx9 aden rx9 aden rsr<8> enable load of receive buffer 8 8 rcreg register rx9d downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 83 pic16f627a/628a/648a figure 12-5: asynchronous reception with address detect figure 12-6: asynchronous recept ion with address byte first figure 12-7: asynchronous reception wi th address byte first followed by valid data byte start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 stop bit rb1/rx/dt (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcreg rcif (interrupt flag) word 1 rcreg bit 8 = 0 , data byte bit 8 = 1 , address byte aden = 1 (address match enable) 1 1 note: this timing diagram shows a data byte followed by an address byte. the data byte is not read into the rcreg (receive buffer) because aden = 1 and bit 8 = 0 . start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 stop bit rb1/rx/dt (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcreg rcif (interrupt flag) word 1 rcreg bit 8 = 1 , address byte bit 8 = 0 , data byte aden = 1 (address match enable) 1 1 note: this timing diagram shows an address byte followed by an data byte. the data byte is not read into the rcreg (receive buffer) because aden was not updated (still = 1 ) and bit 8 = 0 . start bit bit 1 bit 0 bit 8 bit 0 stop bit start bit bit 8 stop bit rb1/rx/dt (pin) reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) word 2 rcreg bit 8 = 1 , address byte bit 8 = 0 , data byte aden (address match enable) word 1 rcreg note: this timing diagram shows an address byte followed by an data byte. the data byte is read into the rcreg (receive buffer) because aden was updated after an address match, and was cleared to a 0 , so the contents of the receive shift register (rsr) are read into the receive buffer regardless of the value of bit 8. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 84 ? 2009 microchip technology inc. follow these steps when setting up an asynchronous reception: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. ( section 12.1 usart baud rate generator (brg) ). 3. enable the asynchronous serial port by clearing bit sync and setting bit spen. 4. if interrupts are desired, then set enable bit rcie. 5. if 9-bit reception is desired, then set bit rx9. 6. enable the reception by setting bit cren. 7. flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if an oerr error occurred, clear the error by clearing enable bit cren. table 12-7: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as 0 . shaded cells are not used for asynchronous reception. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 85 pic16f627a/628a/648a 12.3 usart address detect function 12.3.1 usart 9-bit receiver with address detect when the rx9 bit is set in the rcsta register, 9 bits are received and the ninth bit is placed in the rx9d bit of the rcsta register. the usart module has a special provision for multiprocessor communication. multiprocessor communication is enabled by setting the aden bit (rcsta<3>) along with the rx9 bit. the port is now programmed such that when the last bit is received, the contents of the receive shift register (rsr) are transferred to the receive buffer, the ninth bit of the rsr (rsr<8>) is transferred to rx9d, and the receive interrupt is set if and only if rsr<8> = 1 . this feature can be used in a multiprocessor system as follows: a master processor intends to transmit a block of data to one of many slaves. it must first send out an address byte that identifies the target slave. an address byte is identified by setting the ninth bit (rsr<8>) to a 1 (instead of a 0 for a data byte). if the aden and rx9 bits are set in the slaves rcsta register, enabling multiprocessor communication, all data bytes will be ignored. however, if the ninth received bit is equal to a 1 , indicating that the received byte is an address, the slave will be interrupted and the contents of the rsr register will be transferred into the receive buffer. this allows the slave to be interrupted only by addresses, so that the slave can examine the received byte to see if it is being addressed. the addressed slave will then clear its aden bit and prepare to receive data bytes from the master. when aden is enabled (= 1 ), all data bytes are ignored. following the stop bit, the data will not be loaded into the receive buffer, and no interrupt will occur. if another byte is shifted into the rsr register, the previous data byte will be lost. the aden bit will only take effect when the receiver is configured in 9-bit mode (rx9 = 1 ). when aden is disabled (= 0 ), all data bytes are received and the 9th bit can be used as the parity bit. the receive block diagram is shown in figure 12-4. reception is enabled by setting bit cren (rcsta<4>). 12.3.1.1 setting up 9-bit mode with address detect follow these steps when setting up asynchronous reception with address detect enabled: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. initialize the spbrg register for the appropriate baud rate. if a high-speed baud rate is desired, set bit brgh. 3. enable asynchronous communication by setting or clearing bit sync and setting bit spen. 4. if interrupts are desired, then set enable bit rcie. 5. set bit rx9 to enable 9-bit reception. 6. set aden to enable address detect. 7. enable the reception by setting enable bit cren or sren. 8. flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 9. read the 8-bit received data by reading the rcreg register to determine if the device is being addressed. 10. if an oerr error occurred, clear the error by clearing enable bit cren if it was already set. 11. if the device has been addressed (rsr<8> = 1 with address match enabled), clear the aden and rcif bits to allow data bytes and address bytes to be read into the receive buffer and interrupt the cpu. table 12-8: registers associated with asynchronous reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync b r g h trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented locations read as 0 . shaded cells are not used for asynchronous reception. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 86 ? 2009 microchip technology inc. 12.4 usart synchronous master mode in synchronous master mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition enable bit spen (rcsta<7>) is set in order to configure the rb2/tx/ck and rb1/rx/dt i/o pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor transmits the master clock on the ck line. the master mode is entered by setting bit csrc (txsta<7>). 12.4.1 usart synchronous master transmission the usart transmitter block diagram is shown in figure 12-1. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one tcycle), the txreg is empty and interrupt bit, txif (pir1<4>) is set. the interrupt can be enabled/disabled by setting/clearing enable bit txie (pie1<4>). flag bit txif will be set regardless of the state of enable bit txie and cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit trmt (txsta<1>) shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user has to poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. transmission is enabled by setting enable bit txen (txsta<5>). the actual transmission will not occur until the txreg register has been loaded with data. the first data bit will be shifted out on the next available rising edge of the clock on the ck line. data out is stable around the falling edge of the synchronous clock (figure 12-8). the transmission can also be started by first loading the txreg register and then setting bit txen (figure 12-9). this is advantageous when slow baud rates are selected, since the brg is kept in reset when bits txen, cren and sren are clear. setting enable bit txen will start the brg, creating a shift clock immediately. normally, when transmission is first started, the tsr register is empty, so a transfer to the txreg register will result in an immediate transfer to tsr resulting in an empty txreg. back-to-back transfers are possible. clearing enable bit txen during a transmission will cause the transmission to be aborted and will reset the transmitter. the dt and ck pins will revert to high- impedance. if either bit cren or bit sren is set during a transmission, the transmission is aborted and the dt pin reverts to a high-impedance state (for a reception). the ck pin will remain an output if bit csrc is set (internal clock). the transmitter logic however is not reset although it is disconnected from the pins. in order to reset the transmitter, the user has to clear bit txen. if bit sren is set (to interrupt an on-going transmission and receive a single word), then after the single word is received, bit sren will be cleared and the serial port will revert back to transmitting since bit txen is still set. the dt line will immediately switch from high-imped- ance receive mode to transmit and start driving. to avoid this, bit txen should be cleared. in order to select 9-bit transmission, the tx9 (txsta<6>) bit should be set and the ninth bit should be written to bit tx9d (txsta<0>). the ninth bit must be written before writing the 8-bit data to the txreg register. this is because a data write to the txreg can result in an immediate transfer of the data to the tsr register (if the tsr is empty). if the tsr was empty and the txreg was written before writing the new tx9d, the present value of bit tx9d is loaded. follow these steps when setting up a synchronous master transmission: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. initialize the spbrg register for the appropriate baud rate ( section 12.1 usart baud rate generator (brg) ). 3. enable the synchronous master serial port by setting bits sync, spen and csrc. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set bit tx9. 6. enable the transmission by setting bit txen. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. start each transmission by loading data to the txreg register. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 87 pic16f627a/628a/648a table 12-9: registers associated wi th synchronous master transmission figure 12-8: synchro nous transmission figure 12-9: synchronous tran smission (through txen) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented, read as 0 . shaded cells are not used for synchronous master transmission. bit 0 bit 1 bit 7 word 1 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 q1q2q3q4 bit 2 bit 0 bit 1 bit 7 rb1/rx/dt pin rb2/tx/ck pin write to txreg reg txif bit (interrupt flag) trmt txen bit 1 1 word 2 trmt bit write word 1 write word 2 note: sync master mode; spbrg = 0 . continuous transmission of two 8-bit words. rb1/rx/dt pin rb2/tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 88 ? 2009 microchip technology inc. 12.4.2 usart synchronous master reception once synchronous mode is selected, reception is enabled by setting either enable bit sren (rcsta<5>) or enable bit cren (rcsta<4>). data is sampled on the rb1/rx/dt pin on the falling edge of the clock. if enable bit sren is set, then only a single word is received. if enable bit cren is set, the recep- tion is continuous until cren is cleared. if both bits are set, then cren takes precedence. after clocking the last bit, the received data in the receive shift register (rsr) is transferred to the rcreg register (if it is empty). when the transfer is complete, interrupt flag bit rcif (pir1<5>) is set. the actual interrupt can be enabled/disabled by setting/clearing enable bit rcie (pie1<5>). flag bit rcif is a read-only bit which is reset by the hardware. in this case, it is reset when the rcreg register has been read and is empty. the rcreg is a double buffered register (i.e., it is a two- deep fifo). it is possible for two bytes of data to be received and transferred to the rcreg fifo and a third byte to begin shifting into the rsr register. on the clocking of the last bit of the third byte, if the rcreg register is still full, then overrun error bit oerr (rcsta<1>) is set. the word in the rsr will be lost. the rcreg register can be read twice to retrieve the two bytes in the fifo. bit oerr has to be cleared in software (by clearing bit cren). if bit oerr is set, transfers from the rsr to the rcreg are inhibited, so it is essential to clear bit oerr if it is set. the 9th receive bit is buffered the same way as the receive data. reading the rcreg register, will load bit rx9d with a new value, therefore it is essential for the user to read the rcsta register before reading rcreg in order not to lose the old rx9d information. follow these steps when setting up a synchronous master reception: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. initialize the spbrg register for the appropriate baud rate. ( section 12.1 usart baud rate generator (brg) ). 3. enable the synchronous master serial port by setting bits sync, spen and csrc. 4. ensure bits cren and sren are clear. 5. if interrupts are desired, then set enable bit rcie. 6. if 9-bit reception is desired, then set bit rx9. 7. if a single reception is required, set bit sren. for continuous reception, set bit cren. 8. interrupt flag bit rcif will be set when reception is complete and an interrupt will be generated if enable bit rcie was set. 9. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 10. read the 8-bit received data by reading the rcreg register. 11. if an oerr error occurred, clear the error by clearing bit cren. table 12-10: registers associated with synchronous master reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 epie cmie rcie txie ccp1ie tmr2ie tmr1ie -000 0000 -000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as 0 . shaded cells are not used for synchronous master reception. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 89 pic16f627a/628a/648a figure 12-10: synchronous rece ption (master mode, sren) 12.5 usart synchronous slave mode synchronous slave mode differs from the master mode in the fact that the shift clock is supplied externally at the rb2/tx/ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in sleep mode. slave mode is entered by clearing bit csrc (txsta<7>). 12.5.1 usart synchronous slave transmit the operation of the synchronous master and slave modes are identical except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in txreg register. c) flag bit txif will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit txif will now be set. e) if enable bit txie is set, the interrupt will wake the chip from sleep and if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). follow these steps when setting up a synchronous slave transmission: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. enable the synchronous slave serial port by setting bits sync and spen and clearing bit csrc. 3. clear bits cren and sren. 4. if interrupts are desired, then set enable bit txie. 5. if 9-bit transmission is desired, then set bit tx9. 6. enable the transmission by setting enable bit txen. 7. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 8. start transmission by loading data to the txreg register. cren bit rb1/rx/dt pin rb2/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg q3q4q1q2q3q4q1q2q3q4 q2 q1q2q3q4q1q2q3q4 q1q2q3q4q1q2q3 q4q1q2q3q4q1q2q3q4 q1q2q3q4 0 bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 0 q1q2q3q4 note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brg = 0 . downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 90 ? 2009 microchip technology inc. 12.5.2 usart synchronous slave reception the operation of the synchronous master and slave modes is identical except in the case of the sleep mode. also, bit sren is a dont care in slave mode. if receive is enabled by setting bit cren prior to the sleep instruction, then a word may be received during sleep. on completely receiving the word, the rsr register will transfer the data to the rcreg register and if enable bit rcie bit is set, the interrupt generated will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector (0004h). follow these steps when setting up a synchronous slave reception: 1. trisb<1> and trisb<2> should both be set to 1 to configure the rb1/rx/dt and rb2/tx/ck pins as inputs. output drive, when required, is controlled by the peripheral circuitry. 2. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 3. if interrupts are desired, then set enable bit rcie. 4. if 9-bit reception is desired, then set bit rx9. 5. to enable reception, set enable bit cren. 6. flag bit rcif will be set when reception is complete and an interrupt will be generated, if enable bit rcie was set. 7. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if an oerr error occurred, clear the error by clearing bit cren. table 12-11: registers associated with synchronous slave transmission table 12-12: registers associated with synchronous slave reception address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 19h txreg usart transmit data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as 0 . shaded cells are not used for synchronous slave transmission. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por value on all other resets 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 18h rcsta spen rx9 sren cren aden ferr oerr rx9d 0000 000x 0000 000x 1ah rcreg usart receive data register 0000 0000 0000 0000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 98h txsta csrc tx9 txen sync brgh trmt tx9d 0000 -010 0000 -010 99h spbrg baud rate generator register 0000 0000 0000 0000 legend: x = unknown, - = unimplemented read as 0 . shaded cells are not used for synchronous slave reception . downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 91 pic16f627a/628a/648a 13.0 data eeprom memory the eeprom data memory is readable and writable during normal operation (full v dd range). this memory is not directly mapped in the register file space. instead it is indirectly addressed through the special function registers (sfrs). there are four sfrs used to read and write this memory. these registers are: eecon1 eecon2 (not a physically implemented register) eedata eeadr eedata holds the 8-bit data for read/write and eeadr holds the address of the eeprom location being accessed. pic16f627a/628a devices have 128 bytes of data eeprom with an address range from 0h to 7fh. the pic16f648a device has 256 bytes of data eeprom with an address range from 0h to ffh. the eeprom data memory allows byte read and write. a byte write automatically erases the location and writes the new data (erase before write). the eeprom data memory is rated for high erase/write cycles. the write time is controlled by an on-chip timer. the write time will vary with voltage and temperature, as well as from chip-to-chip. please refer to ac specifications for exact limits. when the device is code-protected, the cpu can continue to read and write the data eeprom memory. a device programmer can no longer access this memory. additional information on the data eeprom is available in the pic ? mid-range reference manual (ds33023). register 13-1: eedata C eeprom data register (address: 9ah) register 13-2: eeadr C eeprom address register (address: 9bh) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eedat7 eedat6 eedat5 eedat4 eedat3 eedat2 eedat1 eedat0 bit 7 bit 0 bit 7-0 eedatn : byte value to write to or read from data eeprom memory location. legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eadr7 eadr6 eadr5 eadr4 eadr3 eadr2 eadr1 eadr0 bit 7 bit 0 bit 7 pic16f627a/628a unimplemented address : must be set to 0 pic16f648a eeadr : set to 1 specifies top 128 locations (128-255) of eeprom read/write operation bit 6-0 eeadr : specifies one of 128 locations of eeprom read/write operation legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 92 ? 2009 microchip technology inc. 13.1 eeadr the pic16f648a eeadr register addresses 256 bytes of data eeprom. all eight bits in the register (eeadr<7:0>) are required. the pic16f627a/628a eeadr register addresses only the first 128 bytes of data eeprom so only seven of the eight bits in the register (eeadr<6:0>) are required. the upper bit is address decoded. this means that this bit should always be 0 to ensure that the address is in the 128 byte memory space. 13.2 eecon1 and eecon2 registers eecon1 is the control register with four low order bits physically implemented. the upper-four bits are non- existent and read as 0 s. control bits rd and wr initiate read and write, respectively. these bits cannot be cleared, only set, in software. they are cleared in hardware at completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental, premature termination of a write operation. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation. in these situations, following reset, the user can check the wrerr bit and rewrite the location. the data and address will be unchanged in the eedata and eeadr registers. interrupt flag bit eeif in the pir1 register is set when write is complete. this bit must be cleared in software. eecon2 is not a physical register. reading eecon2 will read all 0 s. the eecon2 register is used exclusively in the data eeprom write sequence. register 13-3: eecon1 C eeprom cont rol register 1 (address: 9ch) u-0 u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 wrerr wren wr rd bit 7 bit 0 bit 7-4 unimplemented : read as 0 bit 3 wrerr : eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset, any wdt reset during normal operation or bor reset) 0 = the write operation completed bit 2 wren : eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the data eeprom bit 1 wr : write control bit 1 = initiates a write cycle. (the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software. 0 = write cycle to the data eeprom is complete bit 0 rd : read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software). 0 = does not initiate an eeprom read legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 93 pic16f627a/628a/648a 13.3 reading the eeprom data memory to read a data memory location, the user must write the address to the eeadr register and then set control bit rd (eecon1<0>). the data is available, in the very next cycle, in the eedata register; therefore it can be read in the next instruction. eedata will hold this value until another read or until it is written to by the user (during a write operation). example 13-1: data eeprom read 13.4 writing to the eeprom data memory to write an eeprom data location, the user must first write the address to the eeadr register and the data to the eedata register. then the user must follow a specific sequence to initiate the write for each byte. example 13-2: data eeprom write the write will not initiate if the above sequence is not followed exactly (write 55h to eecon2, write aah to eecon2, then set wr bit) for each byte. we strongly recommend that interrupts be disabled during this code segment. a cycle count is executed during the required sequence. any number that is not equal to the required cycles to execute the required sequence will cause the data not to be written into the eeprom. additionally, the wren bit in eecon1 must be set to enable write. this mechanism prevents accidental writes to data eeprom due to errant (unexpected) code execution (i.e., lost programs). the user should keep the wren bit clear at all times, except when updating eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, clearing the wren bit will not affect this write cycle. the wr bit will be inhibited from being set unless the wren bit is set. at the completion of the write cycle, the wr bit is cleared in hardware and the ee write complete interrupt flag bit (eeif) is set. the user can either enable this interrupt or poll this bit. the eeif bit in the pir1 registers must be cleared by software. 13.5 write verify depending on the application, good programming practice may dictate that the value written to the data eeprom should be verified (example 13-3) to the desired value to be written. this should be used in applications where an eeprom bit will be stressed near the specification limit. example 13-3: write verify 13.6 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built-in. on power-up, wren is cleared. also when enabled, the power-up timer (72 ms duration) prevents eeprom write. the write initiate sequence and the wren bit together help prevent an accidental write during brown-out, power glitch or software malfunction. bsf status, rp0 ;bank 1 movlw config_addr ; movwf eeadr ;address to read bsf eecon1, rd ;ee read movf eedata, w ;w = eedata bcf status, rp0 ;bank 0 required sequence bsf status, rp0 ;bank 1 bsf eecon1, wren ;enable write bcf intcon, gie ;disable ints. btfsc intcon,gie ;see an576 goto $-2 movlw 55h ; movwf eecon2 ;write 55h movlw aah ; movwf eecon2 ;write aah bsf eecon1,wr ;set wr bit ;begin write bsf intcon, gie ;enable ints. bsf status, rp0 ;bank 1 movf eedata, w bsf eecon1, rd ;read the ;value written ; ;is the value written (in w reg) and ;read (in eedata) the same? ; subwf eedata, w ; btfss status, z ;is difference 0? goto write_err ;no, write error : ;yes, good write : ;continue program downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 94 ? 2009 microchip technology inc. 13.7 using the data eeprom the data eeprom is a high endurance, byte addressable array that has been optimized for the storage of frequently changing information (e.g., program variables or other data that are updated often). when variables in one section change frequently, while variables in another section do not change, it is possible to exceed the total number of write cycles to the eeprom (specification d124) without exceeding the total number of write cycles to a single byte (specifications d120 and d120a). if this is the case, then an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 13-4. example 13-4: data eeprom refresh routine note: if data eeprom is only used to store constants and/or data that changes rarely, an array refresh is likely not required. see specification d124. banksel 0x80 ;select bank1 clrf eeadr ;start at address 0 bcf intcon, gie ;disable interrupts btfsc intcon, gie ;see an576 goto $ - 2 bsf eecon1, wren ;enable ee writes loop bsf eecon1, rd ;retrieve data into eedata movlw 0x55 ;first step of ... movwf eecon2 ;... required sequence movlw 0xaa ;second step of ... movwf eecon2 ;... required sequence bsf eecon1, wr ;start write sequence btfsc eecon1, wr ;wait for write complete goto $ - 1 #ifdef __16f648a ;256 bytes in 16f648a incfsz eeadr, f ;test for end of memory #else ;128 bytes in 16f627a/628a incf eeadr, f ;next address btfss eeadr, 7 ;test for end of memory #endif ;end of conditional assembly goto loop ;repeat for all locations bcf eecon1, wren ;disable ee writes bsf intcon, gie ;enable interrupts (optional) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 95 pic16f627a/628a/648a 13.8 data eeprom operation during code-protect when the device is code-protected, the cpu is able to read and write data to the data eeprom. table 13-1: registers/bits associated with data eeprom address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on power-on reset value on all other resets 9ah eedata eeprom data register xxxx xxxx uuuu uuuu 9bh eeadr eeprom address register xxxx xxxx uuuu uuuu 9ch eecon1 wrerr wren wr rd ---- x000 ---- q000 9dh eecon2 (1) eeprom control register 2 ---- ---- ---- ---- legend: x = unknown, u = unchanged, - = unimplemented read as 0 , q = value depends upon condition. shaded cells are not used by data eeprom. note 1: eecon2 is not a physical register. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 96 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 97 pic16f627a/628a/648a 14.0 special features of the cpu special circuits to deal with the needs of real-time applications are what sets a microcontroller apart from other processors. the pic16f627a/628a/648a family has a host of such features intended to maximize system reliability, minimize cost through elimination of external components, provide power-saving operating modes and offer code protection. these are: 1. osc selection 2. reset 3. power-on reset (por) 4. power-up timer (pwrt) 5. oscillator start-up timer (ost) 6. brown-out reset (bor) 7. interrupts 8. watchdog timer (wdt) 9. sleep 10. code protection 11. id locations 12. in-circuit serial programming? (icsp?) the pic16f627a/628a/648a has a watchdog timer which is controlled by configuration bits. it runs off its own rc oscillator for added reliability. there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 72 ms (nominal) on power-up only, designed to keep the part in reset while the power supply stabilizes. there is also circuitry to reset the device if a brown-out occurs. with these three functions on-chip, most applications need no external reset circuitry. the sleep mode is designed to offer a very low current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up or through an interrupt. several oscillator options are also made available to allow the part to fit the application. the rc oscillator option saves system cost while the lp crystal option saves power. a set of configuration bits are used to select various options. 14.1 configuration bits the configuration bits can be programmed (read as 0 ) or left unprogrammed (read as 1 ) to select various device configurations. these bits are mapped in program memory location 2007h. the user will note that address 2007h is beyond the user program memory space. in fact, it belongs to the special configuration memory space (2000h-3fffh), which can be accessed only during programming. see pic16f627a/628a/648a eeprom memory programming specification (ds41196) for additional information. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 98 ? 2009 microchip technology inc. register 14-1: config C configuration word regist er cp c p d lvp boren mclre fosc2 pwrte wdte f0sc1 f0sc0 bit 13 bit 0 bit 13: cp : flash program memory code protection bit (2) ( pic16f648a ) 1 = code protection off 0 = 0000h to 0fffh code-protected ( pic16f628a ) 1 = code protection off 0 = 0000h to 07ffh code-protected ( pic16f627a ) 1 = code protection off 0 = 0000h to 03ffh code-protected bit 12-9: unimplemented : read as 0 bit 8: cpd : data code protection bit (3) 1 = data memory code protection off 0 = data memory code-protected bit 7: lvp : low-voltage programming enable bit 1 = rb4/pgm pin has pgm function, low-voltage programming enabled 0 = rb4/pgm is digital i/o, hv on mclr must be used for programming bit 6: boren : brown-out reset enable bit (1) 1 = bor reset enabled 0 = bor reset disabled bit 5: mclre : ra5/mclr /v pp pin function select bit 1 = ra5/mclr/ v pp pin function is mclr 0 = ra5/mclr/ v pp pin function is digital input, mclr internally tied to v dd bit 3: pwrte : power-up timer enable bit (1) 1 = pwrt disabled 0 = pwrt enabled bit 2: wdte : watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled bit 4, 1-0: fosc<2:0> : oscillator selection bits (4) 111 = rc oscillator: clkout function on ra6/osc2/clk out pin, resistor and c apacitor on ra7/osc1/clkin 110 = rc oscillator: i/o function on ra6/osc2/clkout pi n, resistor and capacitor on ra7/osc1/clkin 101 = intosc oscillator: clkout function on ra6/ osc2/clkout pin, i/o function on ra7/osc1/clkin 100 = intosc oscillator: i/o function on ra6/osc2 /clkout pin, i/o functi on on ra7/osc1/clkin 011 = ec: i/o function on ra6/osc2/clkout pin, clkin on ra7/osc1/clkin 010 = hs oscillator: high-speed crystal/resonat or on ra6/osc2/clkou t and ra7/osc1/clkin 001 = xt oscillator: crystal/resonator on ra6/osc2/clkout and ra7/osc1/clkin 000 = lp oscillator: low-power crystal on ra6/osc2/clkout and ra7/osc1/clkin note 1: enabling brown-out reset does not automatically enable the power-up timer (pwrt) the way i t does on the pic16f627/628 devices. 2: the code protection scheme has changed from the code protection scheme used on the pic16f627/628 devices. the entire flash program memory needs to be bulk erased to set the cp bit, turning the code protection off. see pic16f627a/628a/648a eeprom memory programming specification (ds41196) for details. 3: the entire data eeprom needs to be bulk erased to set the cpd bit, turning the code protection off. see pic16f627a/ 628a/648a eeprom memory programming specification (ds41196) for details. 4: when mclr is asserted in intosc mode, the internal clock oscillator is disabled. legend: r = readable bit w = writable bit u = unimplemented bit, read as 0 -n = value at por 1 = bit is set 0 = bit is cleared x = bit is unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 99 pic16f627a/628a/648a 14.2 oscillator configurations 14.2.1 oscillator types the pic16f627a/628a/648a can be operated in eight different oscillator options. the user can program three configuration bits (fosc2 through fosc0) to select one of these eight modes: lp low power crystal xt crystal/resonator hs high speed crystal/resonator rc external resistor/capacitor (2 modes) intosc internal precision oscillator (2 modes) ec external clock in 14.2.2 crystal oscillator / ceramic resonators in xt, lp or hs modes a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation (figure 14-1). the pic16f627a/628a/648a oscillator design requires the use of a parallel cut crystal. use of a series cut crystal may give a frequency out of the crystal manufacturers specifications. when in xt, lp or hs modes, the device can have an external clock source to drive the osc1 pin (figure 14-4). figure 14-1: crystal operation (or ceramic resonator) (hs, xt or lp osc configuration) table 14-1: capacitor selection for ceramic resonators table 14-2: capacitor selection for crystal oscillator note 1: a series resistor may be required for at strip cut crystals. 2: see table 14-1 and table 14-2 for recommended values of c1 and c2. c1 (2) c2 (2) xtal osc2 rs (1) osc1 rf sleep pic16f627a/628a/648a f osc mode freq osc1(c1) osc2(c2) xt 455 khz 2.0 mhz 4.0 mhz 22-100 pf 15-68 pf 15-68 pf 22-100 pf 15-68 pf 15-68 pf hs 8.0 mhz 16.0 mhz 10-68 pf 10-22 pf 10-68 pf 10-22 pf note: higher capacitance increases the stability of the oscillator, but also increases the start-up time. these values are for design guidance only. since each resonator has its own characteristics, the user should consult the resonator manufacturer for appropriate values of external compo- nents. mode freq osc1(c1) osc2(c2) lp 32 khz 200 khz 15-30 pf 0-15 pf 15-30 pf 0-15 pf xt 100 khz 2 mhz 4 mhz 68-150 pf 15-30 pf 15-30 pf 150-200 pf 15-30 pf 15-30 pf hs 8 mhz 10 mhz 20 mhz 15-30 pf 15-30 pf 15-30 pf 15-30 pf 15-30 pf 15-30 pf note: higher capacitance increases the stability of the oscillator, but also increases the start-up time. these values are for design guidance only. a series resistor (rs) may be required in hs mode, as well as xt mode, to avoid overdriving crystals with low drive level specification. since each crystal has its own characteristics, the user should consult the crystal manufac- turer for appropriate values of external components. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 100 ? 2009 microchip technology inc. 14.2.3 external crystal oscillator circuit either a prepackaged oscillator can be used or a simple oscillator circuit with ttl gates can be built. prepackaged oscillators provide a wide operating range and better stability. a well-designed crystal oscillator will provide good performance with ttl gates. two types of crystal oscillator circuits can be used; one with series resonance, or one with parallel resonance. figure 14-2 shows implementation of a parallel resonant oscillator circuit. the circuit is designed to use the fundamental frequency of the crystal. the 74as04 inverter performs the 180 phase shift that a parallel oscillator requires. the 4.7 k resistor provides the negative feedback for stability. the 10 k potentiometers bias the 74as04 in the linear region. this could be used for external oscillator designs. figure 14-2: external parallel resonant crystal oscillator circuit figure 14-3 shows a series resonant oscillator circuit. this circuit is also designed to use the fundamental frequency of the crystal. the inverter performs a 180 phase shift in a series resonant oscillator circuit. the 330 k resistors provide the negative feedback to bias the inverters in their linear region. figure 14-3: external series resonant crystal oscillator circuit 14.2.4 precision internal 4 mh z oscillator the internal precision oscillator provides a fixed 4 mhz (nominal) system clock at v dd = 5v and 25 c. see section 17.0 electrical specifications , for informa- tion on variation over voltage and temperature. 14.2.5 external clock in for applications where a clock is already available elsewhere, users may directly drive the pic16f627a/ 628a/648a provided that this external clock source meets the ac/dc timing requirements listed in section 17.6 timing diagrams and specifications . figure 14-4 below shows how an external clock circuit should be configured. figure 14-4: exter nal clock input operation (ec, hs, xt or lp osc configuration) +5v 10k 4.7k 10k 74as04 xtal 10k 74as04 pic16f627a/628a/648a clkin to o t h e r devices c1 c2 330 k 74as04 74as04 pic16f627a/ clkin to o t h e r devices xtal 330 k 74as04 0.1 pf 628a/648a clock from ext. system pic16f627a/628a/648a ra6 ra7/osc1/clkin ra6/osc2/clkout downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 101 pic16f627a/628a/648a 14.2.6 rc oscillator for applications where precise timing is not a requirement, the rc oscillator option is available. the operation and functionality of the rc oscillator is dependent upon a number of variables. the rc oscillator frequency is a function of: supply voltage resistor (r ext ) and capacitor (c ext ) values operating temperature the oscillator frequency will vary from unit-to-unit due to normal process parameter variation. the difference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low c ext values. the user also needs to account for the tolerance of the external r and c components. figure 14-5 shows how the r/c combination is connected. figure 14-5: rc oscillator mode the rc oscillator mode has two options that control the unused osc2 pin. the first allows it to be used as a general purpose i/o port. the other configures the pin as an output providing the f osc signal (internal clock divided by 4) for test or external synchronization purposes. 14.2.7 clkout the pic16f627a/628a/648a can be configured to provide a clock out signal by programming the configuration word. the oscillator frequency, divided by 4 can be used for test purposes or to synchronize other logic. 14.2.8 special feature: dual-speed oscillator modes a software programmable dual-speed oscillator mode is provided when the pic16f627a/628a/648a is configured in the intosc oscillator mode. this feature allows users to dynamically toggle the oscillator speed between 4 mhz and 48 khz nominal in the intosc mode. applications that require low-current power savings, but cannot tolerate putting the part into sleep, may use this mode. there is a time delay associated with the transition between fast and slow oscillator speeds. this oscillator speed transition delay consists of two existing clock pulses and eight new speed clock pulses. during this clock speed transition delay, the system clock is halted causing the processor to be frozen in time. during this delay, the program counter and the clkout stop. the oscf bit in the pcon register is used to control dual speed mode. see section 4.2.2.6 pcon register , register 4-6. 14.3 reset the pic16f627a/628a/648a differentiates between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during sleep d) wdt reset (normal operation) e) wdt wake-up (sleep) f) brown-out reset (bor) some registers are not affected in any reset condition; their status is unknown on por and unchanged in any other reset. most other registers are reset to a reset state on power-on reset, brown-out reset, mclr reset, wdt reset and mclr reset during sleep. they are not affected by a wdt wake-up, since this is viewed as the resumption of normal operation. to and pd bits are set or cleared differently in different reset situations as indicated in table 14-4. these bits are used in software to determine the nature of the reset. see table 14-7 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 14-6. the mclr reset path has a noise filter to detect and ignore small pulses. see table 17-7 for pulse width specification. c ext v dd r ext v ss pic16f627a/628a/648a f osc /4 internal clock clkin ra7/osc1/ ra6/osc2/clkout recommended values: 3 k r ext 100 k (v dd 3.0v) 10 k r ext 100 k (v dd < 3.0v) c ext > 20 pf downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 102 ? 2009 microchip technology inc. figure 14-6: simplified block di agram of on-chip reset circuit s r q external reset mclr / v dd osc1/ wdt module v dd rise detect ost/pwrt wdt time-out power-on reset ost pwrt chip_reset 10-bit ripple-counter reset enable ost enable pwrt sleep see table 14-3 for time out situations. note 1: this is a separate oscillator from the intosc/rc oscillator. brown-out reset boren clkin pin v pp pin 10-bit ripple-counter q schmitt trigger input on-chip (1) osc downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 103 pic16f627a/628a/648a 14.4 power-on reset (por), power-up timer (pwrt), oscillator start-up timer (ost) and brown-out reset (bor) 14.4.1 power-on reset (por) the on-chip por holds the part in reset until a v dd rise is detected (in the range of 1.2-1.7v). a maxi- mum rise time for v dd is required. see section 17.0 electrical specifications for details. the por circuit does not produce an internal reset when v dd declines. when the device starts normal operation (exits the reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure proper operation. if these conditions are not met, the device must be held in reset via mclr , bor or pwrt until the operating conditions are met. for additional information, refer to application note an607 power-up trouble shooting (ds00607). 14.4.2 power-up timer (pwrt) the pwrt provides a fixed 72 ms (nominal) time out on power-up (por) or if enabled from a brown-out reset. the pwrt operates on an internal rc oscilla- tor. the chip is kept in reset as long as pwrt is active. the pwrt delay allows the v dd to rise to an accept- able level. a configuration bit, pwrte can disable (if set) or enable (if cleared or programmed) the pwrt. it is recommended that the pwrt be enabled when brown-out reset is enabled. the power-up time delay will vary from chip-to-chip and due to v dd , temperature and process variation. see dc parameters table 17-7 for details. 14.4.3 oscillator start-up timer (ost) the ost provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over. program execution will not start until the ost time out is complete. this ensures that the crystal oscillator or resonator has started and stabilized. the ost time out is invoked only for xt, lp and hs modes and only on power-on reset or wake-up from sleep. see table 17-7. 14.4.4 brown-out reset (bor) the pic16f627a/628a/648a have on-chip bor circuitry. a configuration bit, boren, can disable (if clear/programmed) or enable (if set) the bor circuitry. if v dd falls below v bor for longer than t bor , the brown-out situation will reset the chip. a reset is not assured if v dd falls below v bor for shorter than t bor . v bor and t bor are defined in table 17-2 and table 17-7, respectively. on any reset (power-on, brown-out, watchdog, etc.), the chip will remain in reset until v dd rises above v bor (see figure 14-7). the power-up timer will now be invoked, if enabled, and will keep the chip in reset an additional 72 ms. if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be re-initialized. once v dd rises above v bor , the power-up timer will execute a 72 ms reset. figure 14-7 shows typical brown-out situations. figure 14-7: brown-out situat ions with pwrt enabled 72 ms v bor v dd internal reset v bor v dd internal reset 72 ms <72 ms 72 ms v bor v dd internal reset t bor note: 72 ms delay only if pwrte bit is programmed to 0 . downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 104 ? 2009 microchip technology inc. 14.4.5 time out sequence on power-up, the time out sequence is as follows: first pwrt time-out is invoked after por has expired. then ost is activated. the total time out will vary based on oscillator configuration and pwrte bit status. for example, in rc mode with pwrte bit set (pwrt disabled), there will be no time out at all. figure 14-8, figure 14-11 and figure 14-12 depict time out sequences. since the time outs occur from the por pulse, if mclr is kept low long enough, the time outs will expire. then bringing mclr high will begin execution immediately (see figure 14-11). this is useful for testing purposes or to synchronize more than one pic16f627a/628a/ 648a device operating in parallel. table 14-6 shows the reset conditions for some special registers, while table 14-7 shows the reset conditions for all the registers. 14.4.6 power control (pcon) status register the pcon/status register, pcon (address 8eh), has two bits. bit 0 is bor (brown-out reset). bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor = 0 indicating that a brown-out has occurred. the bor status bit is a dont care and is not necessarily predictable if the brown-out circuit is disabled (by setting boren bit = 0 in the configuration word). bit 1 is por (power-on reset). it is a 0 on power-on reset and unaffected otherwise. the user must write a 1 to this bit following a power-on reset. on a subsequent reset if por is 0 , it will indicate that a power-on reset must have occurred (v dd may have gone too low). table 14-3: time out in various situations table 14-4: status/pcon bits and their significance oscillator configuration power-up timer brown-out reset wake-up from sleep pwrte = 0 pwrte = 1 pwrte = 0 pwrte = 1 xt, hs, lp 72 ms + 1024t osc 1024t osc 72 ms + 1024t osc 1024t osc 1024t osc rc, ec 72 ms 72 ms intosc 72 ms 72 ms 6 s por bor to pd condition 0x11 power-on reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 10xx brown-out reset 110u wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep legend: u = unchanged, x = unknown downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 105 pic16f627a/628a/648a table 14-5: summary of registers associated with brown-out reset table 14-6: initialization condition for special registers address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset value on all other resets (1) 03h, 83h, 103h, 183h status irp rp1 rpo to pd z dc c 0001 1xxx 000q quuu 8eh pcon oscf p o r bor ---- 1-0x ---- u-uq legend: x = unknown, u = unchanged, - = unimplemented read as 0 , q = value depends upon condition. shaded cells are not used by brown-out reset. note 1: other (non power-up) resets include mclr reset, brown-out reset and watchdog timer reset during normal operation. condition program counter status register pcon register power-on reset 000h 0001 1xxx ---- 1-0x mclr reset during normal operation 000h 000u uuuu ---- 1-uu mclr reset during sleep 000h 0001 0uuu ---- 1-uu wdt reset 000h 0000 uuuu ---- 1-uu wdt wake-up pc + 1 uuu0 0uuu ---- u-uu brown-out reset 000h 000x xuuu ---- 1-u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- u-uu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as 0 . note 1: when the wake-up is due to an interrupt and global enable bit, gie is set, the pc is loaded with the interrupt vector (0004h) after execution of pc + 1. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 106 ? 2009 microchip technology inc. table 14-7: initialization condition for registers register address power-on reset mclr reset during normal operation mclr reset during sleep wdt reset brown-out reset (1) wake-up from sleep (7) through interrupt wake-up from sleep (7) through wdt time out w xxxx xxxx uuuu uuuu uuuu uuuu indf 00h, 80h, 100h, 180h tmr0 01h, 101h xxxx xxxx uuuu uuuu uuuu uuuu pcl 02h, 82h, 102h, 182h 0000 0000 0000 0000 pc + 1 (3) status 03h, 83h, 103h, 183h 0001 1xxx 000q quuu (4) uuuq 0uuu (4) fsr 04h, 84h, 104h, 184h xxxx xxxx uuuu uuuu uuuu uuuu porta 05h xxxx 0000 xxxx 0000 uuuu uuuu portb 06h, 106h xxxx xxxx uuuu uuuu uuuu uuuu pclath 0ah, 8ah, 10ah, 18ah ---0 0000 ---0 0000 ---u uuuu intcon 0bh, 8bh, 10bh,18bh 0000 000x 0000 000u uuuu uqqq (2) pir1 0ch 0000 -000 0000 -000 qqqq -qqq (2) tmr1l 0eh xxxx xxxx uuuu uuuu uuuu uuuu tmr1h 0fh xxxx xxxx uuuu uuuu uuuu uuuu t1con 10h --00 0000 --uu uuuu (6) --uu uuuu tmr2 11h 0000 0000 0000 0000 uuuu uuuu t2con 12h -000 0000 -000 0000 -uuu uuuu ccpr1l 15h xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h 16h xxxx xxxx uuuu uuuu uuuu uuuu ccp1con 17h --00 0000 --00 0000 --uu uuuu rcsta 18h 0000 000x 0000 000x uuuu uuuu txreg 19h 0000 0000 0000 0000 uuuu uuuu rcreg 1ah 0000 0000 0000 0000 uuuu uuuu cmcon 1fh 0000 0000 0000 0000 uu-- uuuu option 81h,181h 1111 1111 1111 1111 uuuu uuuu trisa 85h 1111 1111 1111 1111 uuuu uuuu trisb 86h, 186h 1111 1111 1111 1111 uuuu uuuu pie1 8ch 0000 -000 0000 -000 uuuu -uuu pcon 8eh ---- 1-0x ---- 1-uq (1,5) ---- u-uu pr2 92h 1111 1111 1111 1111 uuuu uuuu txsta 98h 0000 -010 0000 -010 uuuu -uuu spbrg 99h 0000 0000 0000 0000 uuuu uuuu eedata 9ah xxxx xxxx uuuu uuuu uuuu uuuu eeadr 9bh xxxx xxxx uuuu uuuu uuuu uuuu eecon1 9ch ---- x000 ---- q000 ---- uuuu eecon2 9dh vrcon 9fh 000- 0000 000- 0000 uuu- uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, reads as 0 , q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 14-6 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . 6: reset to --00 0000 on a brown-out reset (bor). 7: peripherals generating interrupts for wake-up from sleep will change the resulting bits in the assoc iated registers. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 107 pic16f627a/628a/648a figure 14-8: time out sequence on power-up (mclr not tied to v dd ): case figure 14-9: time out sequence on power-up (mclr not tied to v dd ): case 2 figure 14-10: time out sequence on power-up (mclr tied to v dd ) t pwrt t ost v dd mclr internal por pwrt time out ost time out internal reset v dd mclr internal por pwrt time out ost time out internal reset t pwrt t ost t pwrt t ost v dd mclr internal por pwrt time out ost time out internal reset downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 108 ? 2009 microchip technology inc. figure 14-11: external power-on reset circuit (for slow v dd power-up) figure 14-12: external brown-out protection circuit 1 figure 14-13: external brown-out protection circuit 2 note 1: external power-on reset circuit is required only if v dd power-up slope is too slow. the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k is recommended to make sure that voltage drop across r does not violate the devices electrical specification. 3: r1 = 100 to 1 k will limit any current flowing into mclr from external capacitor c in the event of mclr /v pp pin break- down due to electrostatic discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic16f627a/628a/648a v dd note 1: this circuit will activate reset when v dd goes below (vz + 0.7v) where vz = zener voltage. 2: internal brown-out reset circuitry should be disabled when using this circuit. v dd 33k 10k 40k v dd mclr pic16f627a/628a/648a x r1 r1 + r2 = 0.7 v v dd r2 40k v dd mclr pic16f627a/628a/648a r1 q1 note 1: this brown-out circuit is less expensive, albeit less accurate. transistor q1 turns off when v dd is below a certain level such that: 2: internal brown-out reset should be disabled when using this circuit. 3: resistors should be adjusted for the characteristics of the transistor. v dd x r1 r1 + r2 = 0.7 v downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 109 pic16f627a/628a/648a 14.5 interrupts the pic16f627a/628a/648a has 10 sources of interrupt: external interrupt rb0/int tmr0 overflow interrupt portb change interrupts (pins rb<7:4>) comparator interrupt usart interrupt tx usart interrupt rx ccp interrupt tmr1 overflow interrupt tmr2 match interrupt data eeprom interrupt the interrupt control register (intcon) records individual interrupt requests in flag bits. it also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>) enables (if set) all un-masked interrupts or disables (if cleared) all interrupts. individual interrupts can be disabled through their corresponding enable bits in intcon register. gie is cleared on reset. the return-from-interrupt instruction, retfie , exits interrupt routine as well as sets the gie bit, which re- enables rb0/int interrupts. the int pin interrupt, the rb port change interrupt and the tmr0 overflow interrupt flags are contained in the intcon register. the peripheral interrupt flag is contained in the special register pir1. the corresponding interrupt enable bit is contained in special registers pie1. when an interrupt is responded to, the gie is cleared to disable any further interrupt, the return address is pushed into the stack and the pc is loaded with 0004h. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid rb0/ int recursive interrupts. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends when the interrupt event occurs (figure 14-15). the latency is the same for one or two-cycle instructions. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid multiple interrupt requests. figure 14-14: interrupt logic note 1: individual interrupt flag bits are set regardless of the status of their corresponding mask bit or the gie bit. 2: when an instruction that clears the gie bit is executed, any interrupts that were pending for execution in the next cycle are ignored. the cpu will execute a nop in the cycle immediately following the instruction which clears the gie bit. the interrupts which were ignored are still pending to be serviced when the gie bit is set again. tmr2if tmr2ie ccp1if ccp1ie cmif cmie txif txie rcif rcie t0if t0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) (1) interrupt to cpu eeie eeif tmr1if tmr1ie note 1: some peripherals depend upon the system clock for operation. since the system cl ock is suspended during sleep, only those peripherals which do not depend upon the system clock will wake the part from sleep. see section 14.8.1 wake-up from sleep . downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 110 ? 2009 microchip technology inc. 14.5.1 rb0/int interrupt external interrupt on the rb0/int pin is edge triggered; either rising if intedg bit (option<6>) is set, or falling, if intedg bit is clear. when a valid edge appears on the rb0/int pin, the intf bit (intcon<1>) is set. this interrupt can be disabled by clearing the inte control bit (intcon<4>). the intf bit must be cleared in software in the interrupt service routine before re-enabling this interrupt. the rb0/int interrupt can wake-up the processor from sleep, if the inte bit was set prior to going into sleep. the status of the gie bit decides whether or not the processor branches to the interrupt vector following wake-up. see section 14.8 power-down mode (sleep) for details on sleep, and figure 14-17 for timing of wake-up from sleep through rb0/int interrupt. 14.5.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set the t0if (intcon<2>) bit. the interrupt can be enabled/ disabled by setting/clearing t0ie (intcon<5>) bit. for operation of the timer0 module, see section 6.0 timer0 module . 14.5.3 portb interrupt an input change on portb <7:4> sets the rbif (intcon<0>) bit. the interrupt can be enabled/disabled by setting/clearing the rbie (intcon<3>) bit. for operation of portb ( section 5.2 portb and trisb registers ). 14.5.4 comparator interrupt see section 10.6 comparator interrupts for complete description of comparator interrupts. figure 14-15: int pin interrupt timing note: if a change on the i/o pin should occur when the read operation is being executed (starts during the q2 cycle and ends before the start of the q3 cycle), then the rbif interrupt flag may not get set. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 osc1 clkout int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed interrupt latency pc pc + 1 pc + 1 0004h 0005h inst (0004h) inst (0005h) dummy cycle inst (pc) inst (pc + 1) inst (pc - 1) inst (0004h) dummy cycle inst (pc) note 1: intf flag is sampled here (every q1). 2: asynchronous interrupt latency = 3-4 t cy . synchronous latency = 3 t cy , where t cy = instruction cycle time. latency is the same whether inst (pc) is a single cycle or a two-cycle instruction. 3: clkout is available in rc and intosc oscillator mode. 4: for minimum width of int pulse, refer to ac specs. 5: intf is enabled to be set anytime during the q4-q1 cycles. (1) (1) (4) (5) (2) (3) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 111 pic16f627a/628a/648a table 14-8: summary of interrupt registers 14.6 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key registers during an interrupt (e.g., w register and status register). this must be implemented in software. example 14-1 stores and restores the status and w registers. the user register, w_temp, must be defined in a common memory location (i.e., w_temp is defined at 0x70 in bank 0 and is therefore, accessible at 0xf0, 0x170 and 0x1f0). the example 14-1: stores the w register stores the status register executes the isr code restores the status (and bank select bit register) restores the w register example 14-1: saving the status and w registers in ram 14.7 watchdog timer (wdt) the watchdog timer is a free running on-chip rc oscillator which does not require any external components. this rc oscillator is separate from the rc oscillator of the clkin pin. that means that the wdt will run, even if the clock on the osc1 and osc2 pins of the device has been stopped, for example, by execution of a sleep instruction. during normal operation, a wdt time out generates a device reset. if the device is in sleep mode, a wdt time out causes the device to wake-up and continue with normal operation. the wdt can be permanently disabled by programming the configuration bit wdte as clear ( section 14.1 configuration bits ). 14.7.1 wdt period the wdt has a nominal time-out period of 18 ms (with no prescaler). the time-out periods vary with temperature, v dd and process variations from part to part (see dc specifications, table 17-7). if longer time- out periods are desired, a postscaler with a division ratio of up to 1:128 can be assigned to the wdt under software control by writing to the option register. thus, time-out periods up to 2.3 seconds can be realized. the clrwdt and sleep instructions clear the wdt and the postscaler, if assigned to the wdt, and prevent it from timing out and generating a device reset. the to bit in the status register will be cleared upon a watchdog timer time out. 14.7.2 wdt programming considerations it should also be taken in account that under worst case conditions (v dd = min., temperature = max., max. wdt prescaler) it may take several seconds before a wdt time out occurs. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset value on all other resets (1) 0bh, 8bh, 10bh, 18bh intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000u 0ch pir1 eeif cmif rcif txif ccp1if tmr2if tmr1if 0000 -000 0000 -000 8ch pie1 eeie cmie rcie txie ccp1ie tmr2ie tmr1ie 0000 -000 0000 -000 note 1: other (non power-up) resets include mclr reset, brown-out reset and watchdog timer reset during normal operation. movwf w_temp ;copy w to temp register, ;could be in any bank swapf status,w ;swap status to be saved ;into w bcf status,rp0 ;change to bank 0 ;regardless of current ;bank movwf status_temp ;save status to bank 0 ;register ::(isr) : swapf status_temp,w;swap status_temp register ;into w, sets bank to original ;state movwf status ;move w into status ;register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 112 ? 2009 microchip technology inc. figure 14-16: watchdo g timer block diagram table 14-9: summary of watchdog timer registers 14.8 power-down mode (sleep) the power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit in the status register is cleared, the to bit is set, and the oscillator driver is turned off. the i/o ports maintain the status they had, before sleep was executed (driving high, low or high- impedance). for lowest current consumption in this mode, all i/o pins should be either at v dd or v ss with no external circuitry drawing current from the i/o pin and the comparators, and v ref should be disabled. i/o pins that are high-impedance inputs should be pulled high or low externally to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on chip pull-ups on portb should be considered. the mclr pin must be at a logic high level (v ihmc ). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por reset value on all other resets 2007h config lvp boren mclre fosc2 pwrte wdte fosc1 fosc0 uuuu uuuu uuuu uuuu 81h, 181h option rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented read as 0 , q = value depends upon condition. note: shaded cells are not used by the watchdog timer. (figure 6-1) note: t0se, t0cs, psa, ps0-ps2 are bits in the option register. from tmr0 clock source watchdog timer wdt enable bit 01 8 8 to 1 mux ps<2:0> to tmr0 (figure 6-1) 01 psa wdt time-out psa m u x mux 3 wdt postscaler/ tmr0 prescaler note: it should be noted that a reset generated by a wdt time-out does not drive mclr pin low. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 113 pic16f627a/628a/648a 14.8.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin 2. watchdog timer wake-up (if wdt was enabled) 3. interrupt from rb0/int pin, rb port change, or any peripheral interrupt, which is active in sleep. the first event will cause a device reset. the two latter events are considered a continuation of program execution. the to and pd bits in the status register can be used to determine the cause of device reset. pd bit, which is set on power-up, is cleared when sleep is invoked. to bit is cleared if wdt wake-up occurred. when the sleep instruction is being executed, the next instruction (pc + 1) is pre-fetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the interrupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have an nop after the sleep instruction. the wdt is cleared when the device wakes up from sleep, regardless of the source of wake-up. figure 14-17: wake-up from sleep through interrupt 14.9 code protection with the code-protect bit is cleared (code-protect enabled), the contents of the program memory locations are read out as 0 . see pic16f627a/628a/ 648a eeprom memory programming specification (ds41196) for details. 14.10 user id locations four memory locations (2000h-2003h) are designated as user id locations where the user can store checksum or other code-identification numbers. these locations are not accessible during normal execution but are readable and writable during program/verify. only the least significant 4 bits of the user id locations are used for checksum calculations although each location has 14 bits. note: if the global interrupts are disabled (gie is cleared), but any interrupt source has both its interrupt enable bit and the corresponding interrupt flag bits set, the device will not enter sleep. the sleep instruction is executed as a nop instruction. q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clkout (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc + 1 pc + 2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency ( note 2 ) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h (3) 0005h dummy cycle t ost (1,2) pc + 2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024 t osc (drawing not to scale). approximately 1 s delay will be there for rc oscillator mode. 3: gie = 1 assumed. in this case, after wake-up the processor jumps to the interrupt routine. if gie = 0 , execution will continue in-line. 4: clkout is not available in these oscillator modes, but shown here for timing reference. note: only a bulk erase function can set the cp and cpd bits by turning off the code protection. the entire data eeprom and flash program memory will be erased to turn the code protection off. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 114 ? 2009 microchip technology inc. 14.11 in-circuit serial programming? (icsp?) the pic16f627a/628a/648a microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data, and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or custom firmware to be programmed. the device is placed into a program/verify mode by holding the rb6 and rb7 pins low while raising the mclr (v pp ) pin from v il to v ihh . see pic16f627a/ 628a/648a eeprom memory programming specification (ds41196) for details. rb6 becomes the programming clock and rb7 becomes the programming data. both rb6 and rb7 are schmitt trigger inputs in this mode. after reset, to place the device into programming/verify mode, the program counter (pc) is at location 00h. a 6-bit command is then supplied to the device. depending on the command, 14 bits of program data are then supplied to or from the device, depending if the command was a load or a read. for complete details of serial programming, please refer to pic16f627a/628a/648a eeprom memory programming specification (ds41196). a typical in-circuit serial programming connection is shown in figure 14-18. figure 14-18: typical in-circuit serial programming connection 14.12 low-voltage programming the lvp bit of the configuration word, enables the low- voltage programming. this mode allows the microcontroller to be programmed via icsp using only a 5v source. this mode removes the requirement of v ihh to be placed on the mclr pin. the lvp bit is normally erased to 1 which enables the low-voltage programming. in this mode, the rb4/pgm pin is dedicated to the programming function and ceases to be a general purpose i/o pin. the device will enter programming mode when a 1 is placed on the rb4/ pgm pin. the high-voltage programming mode is still available by placing v ihh on the mclr pin. if low-voltage programming mode is not used, the lvp bit should be programmed to a 0 so that rb4/ pgm becomes a digital i/o pin. to program the device, v ihh must be placed onto mclr during programming. the lvp bit may only be programmed when program- ming is entered with v ihh on mclr . the lvp bit cannot be programmed when programming is entered with rb4/pgm. it should be noted, that once the lvp bit is programmed to 0 , only high-voltage programming mode can be used to program the device. external connector signals to n o r m a l connections to n o r m a l connections pic16f627a/628a/648a v dd v ss ra5/mclr /v pp rb6/pgc rb7/pgd +5v 0v v pp clk data i/o v dd note 1: while in this mode, the rb4 pin can no longer be used as a general purpose i/o pin. 2: v dd must be 5.0v + 10% during erase operations. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 115 pic16f627a/628a/648a 14.13 in-circuit debugger since in-circuit debugging requires the loss of clock, data and mclr pins, mplab ? icd 2 development with an 18-pin device is not practical. a special 28-pin pic16f648a-icd device is used with mplab icd 2 to provide separate clock, data and mclr pins and frees all normally available pins to the user. debugging of all three versions of the pic16f627a/628a/648a is supported by the pic16f648a-icd. this special icd device is mounted on the top of a header and its signals are routed to the mplab icd 2 connector. on the bottom of the header is an 18-pin socket that plugs into the users target via an 18-pin stand-off connector. when the icd pin on the pic16f648a-icd device is held low, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab icd 2. when the microcontroller has this feature enabled, some of the resources are not available for general use. table 14-19 shows which features are consumed by the background debugger. table 14-19: debugger resources the pic16f648a-icd device with header is supplied as an assembly. see microchip part number ac162053. i/o pins icdclk, icddata stack 1 level program memory address 0h must be nop 300h-3feh downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 116 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 117 pic16f627a/628a/648a 15.0 instruction set summary each pic16f627a/628a/648a instruction is a 14-bit word divided into an opcode which specifies the instruction type and one or more operands which further specify the operation of the instruction. the pic16f627a/628a/648a instruction set summary in table 15-2 lists byte-oriented , bit-oriented , and literal and control operations. table 15-1 shows the opcode field descriptions. for byte-oriented instructions, f represents a file register designator and d represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if d is zero, the result is placed in the w register. if d is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, b represents a bit field designator which selects the number of the bit affected by the operation, while f represents the number of the file in which the bit is located. for literal and control operations, k represents an eight or eleven bit constant or literal value. 15.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (r-m-w) operation. the register is read, the data is modified, and the result is stored according to either the instruc- tion, or the destination designator d. a read operation is performed on a register even if the instruction writes to that register. for example, a clrf portb instruction will read portb, clear all the data bits, then write the result back to portb. this example would have the unin- tended result that the condition that sets the rbif flag would be cleared for pins configured as inputs and using the portb interrupt-on-change feature. table 15-1: opcode field descriptions the instruction set is highly orthogonal and is grouped into three basic categories: byte-oriented operations bit-oriented operations literal and control operations all instructions are executed within one single instruction cycle, unless a conditional test is true or the program counter is changed as a result of an instruction. in this case, the execution takes two instruction cycles with the second cycle executed as a nop . one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. table 15-2 lists the instructions recognized by the mpasm? assembler. figure 15-1 shows the three general formats that the instructions can have. all examples use the following format to represent a hexadecimal number: 0xhh where h signifies a hexadecimal digit. figure 15-1: general format for instructions field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x dont care location (= 0 or 1 ) the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w, d = 1 : store result in file register f. default is d = 1 to time-out bit pd power-down bit note 1: any unused opcode is reserved. use of any reserved opcode may cause unex- pected operation. 2: to maintain upward compatibility with future pic mcu products, do not use the option and tris instructions. byte-oriented file register operations d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations opcode k (literal) k = 8-bit immediate value opcode k (literal) k = 11-bit immediate value general call and goto instructions only 13 8 7 6 0 13 10 9 7 0 6 13 8 7 0 13 11 10 0 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 118 ? 2009 microchip technology inc. table 15-2: pic16f627a/628a/648a instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f f, d f, d f, d f, d f, d f, d f, d f f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 11 1 1 1 1 1 (2) 1 1 (2) 11 1 1 1 1 1 1 1 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1, 2 1, 2 2 1, 2 1, 2 1, 2, 3 1, 2 1, 2, 3 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 11 1 (2) 1 (2) 0101 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1, 2 1, 2 33 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw kk k kk k k kk add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 11 2 1 2 1 1 2 2 2 1 1 1 1111 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to ,pd zto ,pd c,dc,z z note 1: when an i/o register is modified as a function of itself (e.g., movf portb, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is 1 for a pin configured as input and is driven low by an external device, the data will be written back with a 0 . 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is exe cuted as a nop . downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 119 pic16f627a/628a/648a 15.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z encoding: 11 111x kkkk kkkk description: the contents of the w register are added to the eight bit literal k and the result is placed in the w register. words: 1 cycles: 1 example addlw 0x15 before instruction w = 0x10 after instruction w = 0x25 addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [ 0,1 ] operation: (w) + (f) (dest) status affected: c, dc, z encoding: 00 0111 dfff ffff description: add the contents of the w register with register f. if d is 0 , the result is stored in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example addwf reg1, 0 before instruction w=0 x 1 7 reg1 = 0xc2 after instruction w=0 x d 9 reg1 = 0xc2 z= 0 c=0 dc = 0 andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z encoding: 11 1001 kkkk kkkk description: the contents of w register are anded with the eight bit literal k. the result is placed in the w register. words: 1 cycles: 1 example andlw 0x5f before instruction w=0xa3 after instruction w = 0x03 andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [ 0,1 ] operation: (w) .and. (f) (dest) status affected: z encoding: 00 0101 dfff ffff description: and the w register with register f. if d is 0 , the result is stored in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example andwf reg1, 1 before instruction w= 0 x 1 7 reg1 = 0xc2 after instruction w= 0 x 1 7 reg1 = 0x02 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 120 ? 2009 microchip technology inc. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none encoding: 01 00bb bfff ffff description: bit b in register f is cleared. words: 1 cycles: 1 example bcf reg1, 7 before instruction reg1 = 0xc7 after instruction reg1 = 0x47 bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none encoding: 01 01bb bfff ffff description: bit b in register f is set. words: 1 cycles: 1 example bsf reg1, 7 before instruction reg1 = 0x0a after instruction reg1 = 0x8a btfsc bit test f, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none encoding: 01 10bb bfff ffff description: if bit b in register f is 0 , then the next instruction is skipped. if bit b is 0 , then the next instruction fetched during the current instruction execution is discarded, and a nop is executed instead, making this a two-cycle instruction. words: 1 cycles: 1(2) example herefalse true btfscgoto ? ? ? reg1process_code before instruction pc = address here after instruction if reg<1> = 0 , pc = address true if reg<1> = 1 , pc = address false downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 121 pic16f627a/628a/648a btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none encoding: 01 11bb bfff ffff description: if bit b in register f is 1 , then the next instruction is skipped. if bit b is 1 , then the next instruction fetched during the current instruction execution, is discarded and a nop is executed instead, making this a two-cycle instruction. words: 1 cycles: 1(2) example here false true btfssgoto ? ? ? reg1process_code before instruction pc = address here after instruction if flag<1> = 0 , pc = address false if flag<1> = 1 , pc = address true call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none encoding: 10 0kkk kkkk kkkk description: call subroutine. first, return address (pc + 1) is pushed onto the stack. the eleven bit imme- diate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. words: 1 cycles: 2 example here call there before instruction pc = address here after instruction pc = address there tos = address here+1 clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z encoding: 00 0001 1fff ffff description: the contents of register f are cleared and the z bit is set. words: 1 cycles: 1 example clrf reg1 before instruction reg1 = 0x5a after instruction reg1 = 0x00 z= 1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 122 ? 2009 microchip technology inc. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z encoding: 00 0001 0000 0011 description: w register is cleared. zero bit (z) is set. words: 1 cycles: 1 example clrw before instruction w = 0x5a after instruction w = 0x00 z= 1 clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd encoding: 00 0000 0110 0100 description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. words: 1 cycles: 1 example clrwdt before instruction wdt counter = ? after instruction wdt counter = 0x00 wdt prescaler = 0 to = 1 pd = 1 comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f ) (dest) status affected: z encoding: 00 1001 dfff ffff description: the contents of register f are complemented. if d is 0 , the result is stored in w. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example comf reg1, 0 before instruction reg1 = 0x13 after instruction reg1 = 0x13 w=0 x e c decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (dest) status affected: z encoding: 00 0011 dfff ffff description: decrement register f. if d is 0 . the result is stored in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example decf cnt, 1 before instruction cnt = 0x01 z= 0 after instruction cnt = 0x00 z= 1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 123 pic16f627a/628a/648a decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (dest); skip if result = 0 status affected: none encoding: 00 1011 dfff ffff description: the contents of register f are decremented. if d is 0 , the result is placed in the w register. if d is 1 , the result is placed back in register f. if the result is 0 , the next instruction, which is already fetched, is discarded. a nop is executed instead making it a two-cycle instruction. words: 1 cycles: 1(2) example here decfsz reg1, 1 goto loop continue ? ? ? before instruction pc = address here after instruction reg1 = reg1 - 1 if reg1 = 0 , pc = address continue if reg1 0 , pc = address here+1 goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none encoding: 10 1kkk kkkk kkkk description: goto is an unconditional branch. the eleven-bit immedi- ate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. words: 1 cycles: 2 example goto there after instruction pc = address there downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 124 ? 2009 microchip technology inc. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (dest) status affected: z encoding: 00 1010 dfff ffff description: the contents of register f are incremented. if d is 0 , the result is placed in the w register. if d is 1 , the result is placed back in register f. words: 1 cycles: 1 example incf reg1, 1 before instruction reg1 = 0xff z= 0 after instruction reg1 = 0x00 z= 1 incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (dest), skip if result = 0 status affected: none encoding: 00 1111 dfff ffff description: the contents of register f are incremented. if d is 0 , the result is placed in the w register. if d is 1 , the result is placed back in register f. if the result is 0 , the next instruction, which is already fetched, is discarded. a nop is executed instead making it a two-cycle instruction. words: 1 cycles: 1(2) example here incfsz reg1, 1 goto loop continue ? ? ? before instruction pc = address here after instruction reg1 = reg1 + 1 if cnt = 0 , pc = address continue if reg1 0 , pc = address here +1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 125 pic16f627a/628a/648a iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z encoding: 11 1000 kkkk kkkk description: the contents of the w register is ored with the eight-bit literal k. the result is placed in the w register. words: 1 cycles: 1 example iorlw 0x35 before instruction w = 0x9a after instruction w=0xbf z= 0 iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (dest) status affected: z encoding: 00 0100 dfff ffff description: inclusive or the w register with register f. if d is 0 , the result is placed in the w register. if d is 1 , the result is placed back in register f. words: 1 cycles: 1 example iorwf reg1, 0 before instruction reg1 = 0x13 w= 0 x 9 1 after instruction reg1 = 0x13 w= 0 x 9 3 z= 1 movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none encoding: 11 00xx kkkk kkkk description: the eight bit literal k is loaded into w register. the dont cares will assemble as 0 s. words: 1 cycles: 1 example movlw 0x5a after instruction w = 0x5a movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (dest) status affected: z encoding: 00 1000 dfff ffff description: the contents of register f is moved to a destination dependent upon the status of d. if d = 0 , destination is w register. if d = 1 , the destination is file register f itself. d = 1 is useful to test a file register since status flag z is affected. words: 1 cycles: 1 example movf reg1, 0 after instruction w= value in reg1 register z= 1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 126 ? 2009 microchip technology inc. movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none encoding: 00 0000 1fff ffff description: move data from w register to register f. words: 1 cycles: 1 example movwf reg1 before instruction reg1 = 0xff w = 0x4f after instruction reg1 = 0x4f w = 0x4f nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none encoding: 00 0000 0xx0 0000 description: no operation. words: 1 cycles: 1 example nop option load option register syntax: [ label ] option operands: none operation: (w) option status affected: none encoding: 00 0000 0110 0010 description: the contents of the w register are loaded in the option register. this instruction is supported for code compatibility with pic16c5x products. since option is a readable/writable register, the user can directly address it. using only register instruction such as movwf. words: 1 cycles: 1 example to maintain upward compatibil- ity with future pic ? mcu products, do not use this instruction. retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none encoding: 00 0000 0000 1001 description: return from interrupt. stack is poped and top-of-stack (tos) is loaded in the pc. interrupts are enabled by setting global interrupt enable bit, gie (intcon<7>). this is a two- cycle instruction. words: 1 cycles: 2 example retfie after interrupt pc = tos gie = 1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 127 pic16f627a/628a/648a retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none encoding: 11 01xx kkkk kkkk description: the w register is loaded with the eight-bit literal k. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. words: 1 cycles: 2 example table call table;w contains table ;offset value ? ;w now has table value ? ? addwf pc;w = offset retlw k1;begin table retlw k2; ? ? ? retlw kn; end of table before instruction w = 0x07 after instruction w = value of k8 return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none encoding: 00 0000 0000 1000 description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction. words: 1 cycles: 2 example return after interrupt pc = tos rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c encoding: 00 1101 dfff ffff description: the contents of register f are rotated one bit to the left through the carry flag. if d is 0 , the result is placed in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example rlf reg1, 0 before instruction reg1 =1110 0110 c =0 after instruction reg1 =1110 0110 w = 1100 1100 c =1 register f c downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 128 ? 2009 microchip technology inc. rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c encoding: 00 1100 dfff ffff description: the contents of register f are rotated one bit to the right through the carry flag. if d is 0 , the result is placed in the w register. if d is 1 , the result is placed back in register f. words: 1 cycles: 1 example rrf reg1, 0 before instruction reg1 = 1110 0110 c =0 after instruction reg1 = 1110 0110 w = 0111 0011 c =0 sleep syntax: [ labe l ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd encoding: 00 0000 0110 0011 description: the power-down status bit, pd is cleared. time out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. see section 14.8 power-down mode (sleep) for more details. words: 1 cycles: 1 example : sleep register f c sublw subtract w from literal syntax: [ label ]subl w k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z encoding: 11 110x kkkk kkkk description: the w register is subtracted (2s complement method) from the eight- bit literal k. the result is placed in the w register. words: 1 cycles: 1 example 1 : sublw 0x02 before instruction w= 1 c=? after instruction w= 1 c= 1 ; result is positive example 2 : before instruction w= 2 c=? after instruction w= 0 c= 1 ; result is zero example 3 : before instruction w= 3 c= ? after instruction w= 0xff c = 0 ; result is negative downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 129 pic16f627a/628a/648a subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) - (w) ( dest) status affected: c, dc, z encoding: 00 0010 dfff ffff description: subtract (2s complement method) w register from register f. if d is 0 , the result is stored in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example 1 : subwf reg1, 1 before instruction reg1 = 3 w=2 c=? after instruction reg1 = 1 w=2 c= 1 ; result is positive dc = 1 z= 0 example 2 : before instruction reg1 = 2 w=2 c=? after instruction reg1 = 0 w=2 c= 1 ; result is zero z = dc = 1 example 3 : before instruction reg1 = 1 w=2 c=? after instruction reg1 = 0xff w=2 c= 0 ; result is negative z = dc = 0 swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (dest<7:4>), (f<7:4>) (dest<3:0>) status affected: none encoding: 00 1110 dfff ffff description: the upper and lower nibbles of register f are exchanged. if d is 0 , the result is placed in w register. if d is 1 , the result is placed in register f. words: 1 cycles: 1 example swapf reg1, 0 before instruction reg1 = 0xa5 after instruction reg1 = 0xa5 w=0 x 5 a tris load tris register syntax: [ label ] tris f operands: 5 f 7 operation: (w) tris register f; status affected: none encoding: 00 0000 0110 0fff description: the instruction is supported for code compatibility with the pic16c5x products. since tris registers are readable and writable, the user can directly address them. words: 1 cycles: 1 example to maintain upward compatibil- ity with future pic ? mcu products, do not use this instruction. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 130 ? 2009 microchip technology inc. xorlw exclusive or literal with w syntax: [ label ]xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z encoding: 11 1010 kkkk kkkk description: the contents of the w register are xored with the eight-bit literal k. the result is placed in the w register. words: 1 cycles: 1 example : xorlw 0xaf before instruction w=0xb5 after instruction w = 0x1a xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( dest) status affected: z encoding: 00 0110 dfff ffff description: exclusive or the contents of the w register with register f. if d is 0 , the result is stored in the w register. if d is 1 , the result is stored back in register f. words: 1 cycles: 1 example xorwf reg1, 1 before instruction reg1 = 0xaf w=0 x b 5 after instruction reg1 = 0x1a w=0 x b 5 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 131 pic16f627a/628a/648a 16.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: integrated development environment - mplab ? ide software compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families simulators - mplab sim software simulator emulators - mplab real ice? in-circuit emulator in-circuit debuggers - mplab icd 3 - pickit? 3 debug express device programmers - pickit? 2 programmer - mplab pm3 device programmer low-cost demonstration/development boards, evaluation kits, and starter kits 16.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) a full-featured editor with color-coded context a multiple project manager customizable data windows with direct edit of contents high-level source code debugging mouse over variable inspection drag and drop variables from source to watch windows extensive on-line help integration of select third party tools, such as iar c compilers the mplab ide allows you to: edit your source files (either c or assembly) one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 132 ? 2009 microchip technology inc. 16.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchips pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 16.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchips pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 16.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: integration into mplab ide projects user-defined macros to streamline assembly code conditional assembly for multi-purpose source files directives that allow complete control over the assembly process 16.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: efficient linking of single libraries instead of many smaller files enhanced code maintainability by grouping related modules together flexible creation of libraries with easy module listing, replacement, deletion and extraction 16.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: support for the entire device instruction set support for fixed-point and floating-point data command line interface rich directive set flexible macro language mplab ide compatibility downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 133 pic16f627a/628a/648a 16.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 16.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchips next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineers pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers signifi- cant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a rugge- dized probe interface and long (up to three meters) inter- connection cables. 16.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 16.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with users guide, lessons, tutorial, compiler and mplab ide software. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 134 ? 2009 microchip technology inc. 16.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchips flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchips powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with users guide, lessons, tutorial, compiler and mplab ide software. 16.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 16.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page (www.microchip.com) for the complete list of demonstration, development and evaluation kits. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 135 pic16f627a/628a/648a 17.0 electrical specifications absolute maximum ratings(?) ambient temperature under bias................................................................................................. ................ -40 to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on v dd with respect to v ss ............................................................................................................ -0.3 to +6.5v voltage on mclr and ra4 with respect to v ss ............................................................................................-0.3 to +14v voltage on all other pins with respect to v ss ....................................................................................-0.3v to v dd + 0.3v total power dissipation (1) ............................................................................................................................... ......800 mw maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) .................................................................................................... ................. 20 ma output clamp current, i ok (vo < 0 or vo >v dd ) .................................................................................................... ........... 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by porta and portb (combined)................................................................................200 ma maximum current sourced by porta and portb (combined).......................................................................... .200 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd C i oh } + {(v dd C v oh ) x i oh } + (v o l x i ol ) ? notice : stresses above those listed under absolute maximum ratings may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above thos e indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability. note: voltage spikes below v ss at the mclr pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 should be used when applying a low level to the mclr pin rather than pulling this pin directly to v ss . downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 136 ? 2009 microchip technology inc. figure 17-1: pic16f627a/628a/648a voltage-frequency graph, -40 c ta +125 c figure 17-2: pic16lf627a/628a/648a voltage-frequency graph, -40 c ta +85 c 6.0 2.5 4.0 3.0 0 3.5 4.5 5.0 5.5 41 0 frequency (mhz) v dd 20 (volts ) 25 note: the shaded region indicates the permissible combinations of voltage and frequency. 6.02.5 4.03.0 0 3.5 4.5 5.0 5.5 41 0 frequency (mhz) v dd 20 (volts) 25 2.0 note: the shaded region indicates the permissible combinations of voltage and frequency. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 137 pic16f627a/628a/648a 17.1 dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) pic16lf627a/628a/648a (industrial) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial pic16f627a/628a/648a (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial and -40 c ta +125 c for extended param no. sym characteristic/device min typ? max units conditions v dd supply voltage d001 pic16lf627a/628a/648a 2.0 5.5 v pic16f627a/628a/648a 3.0 5.5 v d002 v dr ram data retention voltage (1) 1.5* v device in sleep mode d003 v por v dd start voltage to ensure power-on reset v ss v see section 14.4 power- on reset (por), power-up timer (pwrt), oscillator start-up timer (ost) and brown-out reset (bor) on power-on reset for details d004 s vdd v dd rise rate to ensure power-on reset 0.05* v/ms see section 14.4 power- on reset (por), power-up timer (pwrt), oscillator start-up timer (ost) and brown-out reset (bor) on power-on reset for details d005 v bor brown-out reset voltage 3.65 3.65 4.04.0 4.35 4.4 vv boren configuration bit is set boren configuration bit is set, extended legend: rows with standard voltage device data only are shaded for improved readability. * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c, unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered in sleep mode without losing ram data. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 138 ? 2009 microchip technology inc. 17.2 dc characteristics: pic16f627a/628a/648a (industrial) pic16lf627a/628a/648a (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40 c ta +85 c for industrial param no. lf and f device characteristics min? typ max units conditions v dd note supply voltage (v dd ) d001 lf 2.0 5.5 v lf/f 3.0 5.5 v power-down base current (i pd ) d020 lf 0.01 0.80 a 2.0 wdt, bor, comparators, v ref and t1osc: disabled lf/f 0.01 0.85 a3 . 0 0 . 0 22 . 7 a5 . 0 peripheral module current ( i mod ) (1) d021 lf 1 2.0 a 2.0 wdt current lf/f 2 3.4 a3 . 0 91 7 . 0 a5 . 0 d022 lf/f 29 52 a 4.5 bor current 3 05 5 a5 . 0 d023 lf 15 22 a 2.0 comparator current (both comparators enabled) lf/f 22 37 a3 . 0 4 46 8 a5 . 0 d024 lf 34 55 a2 . 0v ref current lf/f 50 75 a3 . 0 8 01 1 0 a5 . 0 d025 lf 1.2 2.0 a2 . 0t 1 o sc current lf/f 1.3 2.2 a3 . 0 1 . 82 . 9 a5 . 0 supply current (i dd ) d010 lf 10 15 a2 . 0f osc = 32 khz lp oscillator mode lf/f 15 25 a3 . 0 2 84 8 a5 . 0 d011 lf 125 190 a2 . 0f osc = 1 mhz xt oscillator mode lf/f 175 340 a3 . 0 320 520 a5 . 0 d012 lf 250 350 a2 . 0f osc = 4 mhz xt oscillator mode lf/f 450 600 a3 . 0 710 995 a5 . 0 d012a lf 395 465 a2 . 0f osc = 4 mhz intosc lf/f 565 785 a3 . 0 0.895 1.3 ma 5.0 d013 lf/f 2.5 2.9 ma 4.5 f osc = 20 mhz hs oscillator mode 2 . 7 53 . 3 m a 5 . 0 note 1: the current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. max values should be used when calculating total current consumption. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 139 pic16f627a/628a/648a 17.3 dc characteristics: pic16f627a/628a/648a (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40 c ta +125 c for extended param no. device characteristics min? typ max units conditions v dd note supply voltage (v dd ) d001 3.0 5.5 v power-down base current (i pd ) d020e 0 . 0 1 4 a 3.0 wdt, bor, comparators, v ref and t1osc: disabled 0 . 0 2 8 a5 . 0 peripheral module current ( i mod ) (1) d021e 2 9 a3 . 0w d t c u r r e n t 92 0 a5 . 0 d022e 29 52 a 4.5 bor current 3 05 5 a5 . 0 d023e 22 37 a 3.0 comparator current (both comparators enabled) 4 46 8 a5 . 0 d024e 50 75 a3 . 0v ref current 8 31 1 0 a5 . 0 d025e 1 . 3 4 a 3.0 t1osc current 1 . 8 6 a5 . 0 supply current (i dd ) d010e 15 28 a3 . 0f osc = 32 khz lp oscillator mode 2 85 4 a5 . 0 d011e 1 7 5 3 4 0 a3 . 0f osc = 1 mhz xt oscillator mode 3 2 05 2 0 a5 . 0 d012e 4 5 0 6 5 0 a3 . 0f osc = 4 mhz xt oscillator mode 0.710 1.1 ma 5.0 d012ae 5 6 5 7 8 5 a3 . 0f osc = 4 mhz intosc 0.895 1.3 ma 5.0 d013e 2.5 2.9 ma 4.5 f osc = 20 mhz hs oscillator mode 2.75 3.5 ma 5.0 note 1: the current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. max values should be used when calculating total current consumption. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 140 ? 2009 microchip technology inc. 17.4 dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ta +85c for industrial and -40c ta +125c for extended operating voltage v dd range as described in dc specification table 17-2 and table 17-3 param. no. sym characteristic/device min typ? max unit conditions v il input low voltage d030 d031 d032 d033 i/o ports with ttl buffer with schmitt trigger input (4) mclr , ra4/t0cki,osc1 (in rc mode) osc1 (in hs) osc1 (in lp and xt) v ss v ss v ss v ss v ss v ss 0.8 0.15 v dd 0.2 v dd 0.2 v dd 0.3 v dd 0.6 vv v v v v v dd = 4.5v to 5.5v otherwise (note1) v ih input high voltage d040 d041 d042 d043 d043a d043b i/o ports with ttl buffer with schmitt trigger input (4) mclr ra4/t0cki osc1 (xt and lp) osc1 (in rc mode) osc1 (in hs mode) 2.0v .25 v dd + 0.8v 0.8 v dd 0.8 v dd 1.3 0.9 v dd 0.7 v dd v dd v dd v dd v dd v dd v dd v dd vv v v v v v v dd = 4.5v to 5.5v otherwise (note1) d070 i purb portb weak pull-up current 50 200 400 av dd = 5.0v, v pin = v ss i il input leakage current (2), (3) d060 d061 d063 i/o ports (except porta) porta (4) ra4/t0cki osc1, mclr 1.0 0.5 1.0 5.0 a a a a v ss v pin v dd , pin at high-impedance v ss v pin v dd , pin at high-impedance v ss v pin v dd v ss v pin v dd , xt, hs and lp oscillator configuration v ol output low voltage d080 i/o ports (4) 0.60.6 vv i ol = 8.5 ma, v dd = 4.5 v, -40 to +85 c i ol = 7.0 ma, v dd = 4.5 v, +85 to +125 c v oh output high voltage (3) d090 i/o ports (except ra4 (4) )v dd C 0.7 v dd C 0.7 vv i oh = -3.0 ma, v dd = 4.5 v, -40 to +85 c i oh = -2.5 ma, v dd = 4.5 v, +85 to +125 c d150 v od open-drain high voltage 8.5* v ra4 pin pic16f627a/628a/648a, pic16lf627a/628a/648a capacitive loading specs on output pins d100* d101* cosc2 c io osc2 pin all i/o pins/osc2 (in rc mode) 1550 pfpf in xt, hs and lp modes when external clock used to drive osc1. * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1 pin is a schmitt tr igger input. it is not recommended that the pic16f627a/628a/648a be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as coming out of the pin. 4: includes osc1 and osc2 when configured as i/o pins, clkin or clkout. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 141 pic16f627a/628a/648a table 17-1: dc characteristics: pic16f627a/628a/648a (industrial, extended) pic16lf627a/628a/648a (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ta +85c for industrial and -40c ta +125c for extended operating voltage v dd range as described in dc specification table 17-2 and table 17-3 parameter no. sym characteristic min typ? max units conditions data eeprom memory d120 d120a d121 d122 d123 d124 e d e d v drw t dew t retd t ref endurance endurance v dd for read/write erase/write cycle time characteristic retention number of total erase/write cycles before refresh (1) 100k 10k v min 40 1m 1m 100k 4 10m 5.5 8 * e/we/w v ms year e/w -40 c t a 85c 85c t a 125c v min = minimum operating voltage provided no other specifications are violated -40 c to +85c program flash memory d130 d130a d131 d132 d132a d133 d133a d134 e p e p v pr v ie v pew t ie t pew t retp endurance endurance v dd for read v dd for block erase v dd for write block erase cycle time write cycle time characteristic retention 10k 1000 v min 4.5 v min 40 100k 10k 42 5.5 5.5 5.5 8 * 4 * e/we/w vv v msms year -40 c t a 85c 85c t a 125c v min = minimum operating voltage v min = minimum operating voltage v dd > 4.5v provided no other specifications are violated * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: refer to section 13.7 using the data eeprom for a more detailed discussion on data eeprom endurance. downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 142 ? 2009 microchip technology inc. table 17-2: comparator specifications table 17-3: voltage reference specifications operating conditions: 2.0v < v dd < 5.5v, -40c < t a < +125c, unless otherwise stated. param no. characteristics sym min typ max units comments d300 input offset voltage v ioff 5.0 10 mv d301 input common mode voltage v icm 0v dd C 1.5* v d302 common mode rejection ratio cmrr 55* db d303 response time (1) t resp 300 400 400 400* 600* 600* nsns ns v dd = 3.0v to 5.5v -40 to +85c v dd = 3.0v to 5.5v -85 to +125c v dd = 2.0v to 3.0v -40 to +85c d304 comparator mode change to output valid t mc 2 ov 3 0 0 1 0 * s * these parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd C 1.5)/2, while the other input transitions from v ss to v dd . operating conditions: 2.0v < v dd < 5.5v, -40 c < t a < +125 c, unless otherwise stated. spec no. characteristics sym min typ max units comments d310 resolution v res v dd /24 v dd /32 lsblsb low range (vrr = 1 ) high range (vrr = 0 ) d311 absolute accuracy v raa 1/4 (2) * 1/2 (2) * lsblsb low range (vrr = 1 ) high range (vrr = 0 ) d312 unit resistor value (r) v rur 2 k * d313 settling time (1) t set 1 0 * s * these parameters are characterized but not tested. note 1: settling time measured while vrr = 1 and vr<3:0> transitions from 0000 to 1111 . 2: when v dd is between 2.0v and 3.0v, the v ref output voltage levels on ra2 described by the equation:[v dd /2 (3 C v dd )/2] may cause the absolute accuracy (v raa ) of the v ref output signal on ra2 to be greater than the stated max. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 143 pic16f627a/628a/648a 17.5 timing parameter symbology the timing parameter symbols have been created with one of the following formats: figure 17-3: load conditions 1. tpps2pps 2. tpps t f frequency t time lowercase subscripts (pp) and their meanings: pp ck clkout osc osc1 io i/o port t0 t0cki mc mclr uppercase letters and their meanings: s ff a l l p p e r i o d hh i g h r r i s e i invalid (high-impedance) v valid l low z high-impedance v dd /2 cl rl pin pin v ss v ss cl r l =464 c l = 50 pf for all pins except osc2 15 pf for osc2 output l oad c ondition 1 l oad c ondition 2 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 144 ? 2009 microchip technology inc. 17.6 timing diagrams and specifications figure 17-4: extern al clock timing table 17-4: external clock timing requirements parameter no. sym characteristic min typ? max units conditions f osc external clkin frequency (1) dc 4 mhz xt and rc osc mode, v dd = 5.0 v dc 20 mhz hs, ec osc mode dc 200 khz lp osc mode oscillator frequency (1) 4 mhz rc osc mode, v dd = 5.0v 0.1 4 mhz xt osc mode 1 20 200 mhz khz hs osc mode lp osc mode 4 mhz intosc mode (fast) 48 khz intosc mode (slow) 1t osc external clkin period (1) 250 ns xt and rc osc mode 50 ns hs, ec osc mode 5 slp osc mode oscillator period (1) 250 ns rc osc mode 250 10,000 ns xt osc mode 50 1,000 ns hs osc mode 5 slp osc mode 250 ns intosc mode (fast) 2 1 s intosc mode (slow) 2t cy instruction cycle time 200 t cy dc ns t cy = 4/f osc 3t o s l , tos h external clkin (osc1) high external clkin low 100* ns xt oscillator, t osc l/h duty cycle 4 rc external biased rc frequency 10 khz* 4 mhz v dd = 5.0v * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time-based period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator oper- ation and/or higher than expected current consumption. all devices are tested to operate at min values with an external clock applied to the osc1 pin. when an external clock input is used, the max cycle tim e limit is dc (no clock) for all devices. osc1 clkout q4 q1 q2 q3 q4 q1 13 3 44 2 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 145 pic16f627a/628a/648a table 17-5: precision internal oscillator parameters legend: tbd = to be determined. * characterized but not tested. figure 17-5: clko ut and i/o timing parameter no. sym characteristic min typ max units conditions f10 f iosc oscillator center frequency 4m h z f13 i osc oscillator accuracy 3 . 9 644 . 0 4m h z v dd = 3.5 v, 25 c 3.92 4 4.08 mhz 2.0v v dd 5.5v 0 c t a +85 c 3.80 4 4.20 mhz 2.0v v dd 5.5v -40 c t a +85 c (ind) -40 c t a +125 c (ext) f14 * t ioscst oscillator wake-up from sleep start-up time 6 8 sv dd = 2.0v, -40 c to +85 c 4 6 sv dd = 3.0v, -40 c to +85 c 3 5 sv dd = 5.0v, -40 c to +85 c osc1 clkout i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 22 23 19 18 15 11 12 16 old value new value downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 146 ? 2009 microchip technology inc. table 17-6: clkout and i/o timing requirements figure 17-6: reset, watchdog timer, os cillator start-up timer and power-up timer timing parameter no. sym characteristic min typ? max units 10 t os h2 ck losc1 to clkout pic16f62xa 7 5 2 0 0 * n s 10a pic16lf62xa 400* ns 11 t os h2 ck hosc1 to clkout pic16f62xa 75 200* ns 11a pic16lf62xa 400* ns 12 t ck r clkout rise time pic16f62xa 35 100* ns 12a pic16lf62xa 200* ns 13 t ck f clkout fall time pic16f62xa 35 100* ns 13a pic16lf62xa 200* ns 14 t ck l2 io vclkout to port out valid 20* ns 15 t io v2 ck h port in valid before clkout pic16f62xa t osc +200 ns* ns pic16lf62xa t osc +400 ns* ns 16 t ck h2 io i port in hold after clkout 0 ns 17 t os h2 io vosc1 (q1 cycle) to pic16f62xa 50 150* ns port out valid pic16lf62xa 300* ns 18 t os h2 io iosc1 (q2 cycle) to port input invalid (i/o in hold time) 100* 200* n s * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. v dd mclr internal por pwrt time out ost time out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 147 pic16f627a/628a/648a figure 17-7: brown-out reset timing table 17-7: reset, watchdog timer, oscillator start-up timer and power-up timer requirements figure 17-8: timer0 and timer1 external clock timings parameter no. sym characteristic min typ? max units conditions 30 t mc lmclr pulse width (low) 2000 ns v dd = 5v, -40c to +85c 31 t wdt watchdog timer time out period (no prescaler) 7* 18 33* ms v dd = 5v, -40c to +85c 32 t ost oscillation start-up timer period 1024 t osc t osc = osc1 period 33 t pwrt power-up timer period 28* 72 132* ms v dd = 5v, -40c to +85c 34 t ioz i/o high-impedance from mclr low or watchdog timer reset 2.0* s 35 t bor brown-out reset pulse width 100* sv dd v bor (d005) legend: tbd = to be determined. * these parameters are characterized but not tested. ? data in typ column is at 5.0v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. v dd v bor 35 46 47 45 48 41 42 40 ra4/t0cki/cmp2 rb6/t1oso/t1cki/pgc tmr0 or tmr1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 148 ? 2009 microchip technology inc. table 17-8: timer0 and timer1 external clock requirements param no. sym characteristic min typ? max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5t cy + 20* ns with prescaler 10* ns 41 t t 0l t0cki low pulse width no prescaler 0.5t cy + 20* ns with prescaler 10* ns 42 t t 0p t0cki period 20 or greater of: t cy + 40* n ns n = prescale value (2, 4, ..., 256) 45 t t 1h t1cki high time synchronous, no prescaler 0.5t cy + 20* ns synchronous, with prescaler pic16f62xa 15* ns pic16lf62xa 25* ns asynchronous pic16f62xa 30* ns pic16lf62xa 50* ns 46 t t 1l t1cki low time synchronous, no prescaler 0.5t cy + 20* ns synchronous, with prescaler pic16f62xa 15* ns pic16lf62xa 25* ns asynchronous pic16f62xa 30* ns pic16lf62xa 50* ns 47 t t 1p t1cki input period synchronous pic16f62xa 20 or greater of: t cy + 40* n ns n = prescale value (1, 2, 4, 8) pic16lf62xa 20 or greater of: t cy + 40* n asynchronous pic16f62xa 60* ns pic16lf62xa 100* ns f t 1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) 3 2 . 7 (1) khz 48 tckez tmr 1 delay from external clock edge to timer increment 2t osc 7t osc * these parameters are characterized but not tested. ? data in typ column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this oscillator is intended to work only with 32.768 khz watch crystals and their manufactured to lerances. higher value crystal frequencies may not be compatible with this crystal driver. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 149 pic16f627a/628a/648a figure 17-9: capture/compare/pwm timings table 17-9: capture/compare/pwm requirements param no. sym characteristic min typ? max units conditions 50 t cc l ccp input low time no prescaler 0.5t cy + 20* ns with prescaler pic16f62xa 10* ns pic16lf62xa 20* ns 51 t cc h ccp input high time no prescaler 0.5t cy + 20* ns with prescaler pic16f62xa 10* ns pic16lf62xa 20* ns 52 t cc p ccp input period 3t cy + 40* n ns n = prescale value (1,4 or 16) 53 t cc r ccp output rise time pic16f62xa 10 25* ns pic16lf62xa 25 45* ns 54 t cc f ccp output fall time pic16f62xa 10 25* ns pic16lf62xa 25 45* ns * these parameters are characterized but not tested. ? data in typ column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. (capture mode) 50 51 52 53 54 rb3/ccp1 (compare or pwm mode) rb3/ccp1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 150 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 151 pic16f627a/628a/648a 18.0 dc and ac characteristics graphs and tables the graphs and tables provided in this section are for design guidance and are not tested . in some graphs or tables, the data presented are outside specified operating range (i.e., outside specified v dd range). this is for information only and devices are ensured to operate properly only within the specified range. the data presented in this section is a statistical summary of data collected on units from different lots over a period of time and matrix samples. typical represents the mean of the distribution at 25 c. max or min represents (mean + 3 ) or (mean - 3 ) respectively, where is standard deviation, over the whole temperature range. figure 18-1: typical baseline i pd vs. v dd (-40 c to 25 c) 0 20 40 60 80 100 120 140 160 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) i pd (na) -40c 0c +25c downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 152 ? 2009 microchip technology inc. figure 18-2: typical baseline i pd vs. v dd (85 c) figure 18-3: typical baseline current i pd vs. v dd (125 c) 100 120 140 160 180 200 220 240 260 280 300 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) i pd (na) +85c 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) +125c ipd ( a) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 153 pic16f627a/628a/648a figure 18-4: typical bor i pd vs. v dd figure 18-5: typical single comparator i pd vs. v dd 20 22 24 26 28 30 32 34 36 38 40 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) 0 5 10 15 20 25 30 2 2.5 3 3.5 4 4.5 5 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 154 ? 2009 microchip technology inc. figure 18-6: typical v ref i pd vs. v dd figure 18-7: typical wdt i pd vs. v dd 20 30 40 50 60 70 80 90 100 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) 0 2 4 6 8 10 12 14 16 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 155 pic16f627a/628a/648a figure 18-8: average i pd _timer1 figure 18-9: typical internal oscillator frequency vs. temperature v dd = 5 volts 0 1 2 3 4 5 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) i pd (ua) -40c 0c 25c 85c 125 -5.0% -4.0% -3.0% -2.0% -1.0% 0.0% 1.0% 2.0% 3.0% 4.0% 5.0% -40 25 85 125 temperature (oc) change from calibration target (%) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 156 ? 2009 microchip technology inc. figure 18-10: typical internal os cillator frequency vs. temperature v dd = 3 volts figure 18-11: typical internal oscillator frequency vs. temperature v dd = 2 volts -5.0% -4.0% -3.0% -2.0% -1.0% 0.0% 1.0% 2.0% 3.0% 4.0% 5.0% -40 25 85 125 temperature (oc) change from calibration target (%) -5.0% -4.0% -3.0% -2.0% -1.0% 0.0% 1.0% 2.0% 3.0% 4.0% 5.0% -40 25 85 125 temperature (oc) change from calibration target (%) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 157 pic16f627a/628a/648a figure 18-12: typical internal oscillator deviation vs. v dd at 25c C 4 mhz mode figure 18-13: typical internal oscillator frequency vs. v dd temperature = -40c to 85c -5.0% -4.0% -3.0% -2.0% -1.0% 0.0% 1.0% 2.0% 3.0% 4.0% 5.0% 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) change from calibration target (%) -5.0% -4.0% -3.0% -2.0% -1.0% 0.0% 1.0% 2.0% 3.0% 4.0% 5.0% 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) change from calibration target (%) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 158 ? 2009 microchip technology inc. figure 18-14: internal oscillator i dd vs. v dd C 4 mhz mode figure 18-15: typical internal oscillator frequency vs. v dd at 25c C slow mode 0.00 0.20 0.40 0.60 0.80 1.00 1.20 1.40 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) i dd (ma) 85 c 25 c avg -40 c 30 35 40 45 50 55 60 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) oscillator frequency (khz) downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 159 pic16f627a/628a/648a figure 18-16: internal oscillator i dd vs. v dd C slow mode figure 18-17: supply current (i dd vs. v dd , f osc = 1 mhz (xt oscillator mode) 0 20 40 60 80 100 120 140 160 180 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) 85 c 25 c avg -40 c ipd ( a) 100 150 200 250 300 350 400 450 500 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 160 ? 2009 microchip technology inc. figure 18-18: supply current (i dd vs. v dd , f osc = 4 mhz (xt oscillator mode) figure 18-19: supply current (i dd ) vs. v dd , f osc = 20 mhz (hs oscillator mode) 200 300 400 500 600 700 800 900 1000 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (volts) 125c 85c 25c 0c -40c ipd ( a) 2.0 2.5 3.0 3.5 4.0 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 v dd (volts) i dd (ma) 125c 85c 25c 0c -40c downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 161 pic16f627a/628a/648a figure 18-20: typical wdt period vs. v dd (-40 c to +125 c) wdt time-out 0 5 10 15 20 25 30 35 40 45 50 2 2.5 3 3.5 4 4.5 5 5.5 v dd (v) time ( ms) -40 0 25 85 125 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 162 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 163 pic16f627a/628a/648a 19.0 packaging information 19.1 package marking information 18-lead pdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic16f627a 0410017 18-lead soic (.300) xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic16f628a -e/so 0410017 20-lead ssop xxxxxxxxxxx xxxxxxxxxxx yywwnnn example pic16f648a -i/ss 0410017 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 16f628a -i/ml 0410017 3 e 3 e 3 e 3 e -i/p legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week 01) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 164 ? 2009 microchip technology inc. 
    
     

      !"#$%&" '  ()"&'"!&)
&#*& &  & #   +%&,  & !& - '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#/  !#  '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 !   3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 7,8. '!
9'&! 7 7: ; 7"') 
%! 7 < &  1,
&
&  = =  
##4 4!!   -  1!&
&   = = 
"# &

"# >#& . - - - 
##4>#& .   < :  9&  <<    &
& 9  -  9# 4!!  <   6  9#>#& )  ?  9
* 9#>#& )  <  :  
* + 1 = = - note 1 n e1 d 1 23 a a1 a2 l eeb c e b1 b 
   

  * ,1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 165 pic16f627a/628a/648a 
  ! "  !"  #$ %&'   !"(     !"#$%&" '  ()"&'"!&)
&#*& &  & #   +%&,  & !& - '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#''  !#  '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
   3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7 < &  1, :  8 &  = = ? 
##4 4!!   = = &#
%%+   = - :  >#& . -1, 
##4>#& . 1, :  9&  1, , '% @
&
a  =  3
&9& 9  =  3
& & 9 .3 3
&  b = #& ) - =  
# %&
 b = b 
# %&1
&&
'  b = b note 1 d n e e1 e b 1 23 a a1 a2 l l1 h h c 
   

  * ,1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 166 ? 2009 microchip technology inc. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 167 pic16f627a/628a/648a )
  !*+, ! "  !!  '&   !!"
     !"#$%&" '  ()"&'"!&)
&#*& &  & #   '!
!#.#

&"#'
#%! 

& "!
!
#%! 

& "!
!! 
&$#''  !# - '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
   3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7  &  ?1, :  8 &  = =  
##4 4!!  ?  < &#
%%   = = :  >#& .  < < 
##4>#& .  - ? :  9&  ?   3
&9& 9    3
& & 9 .3 9# 4!!   =  3
&  b b #& )  = -< l l1 a2 c e b a1 a 12 note 1 e1 e d n 
   

  * ,1 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 168 ? 2009 microchip technology inc. )
  - .  $  
,/ 0  121   -. 3 * &''  (  / *     !"#$%&" '  ()"&'"!&)
&#*& &  & #   4!!*!"&# - '!
#&
   .0 1,2 1!'!
 
&$& "!
**&
"&&
 ! .32 % '!
("!"*&
"&&
 (%
%
'&
 "
!!
   3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 6&! 99. . '!
9'&! 7 7: ; 7"') 
%! 7 < &  ?1, :  8 &  <   &#
%%     ,
&& 4!! - .3 :  >#& . ?1, .$
!##>#& . -? -  :  9&  ?1, .$
!##9&  -? -  ,
&&>#& ) - - - ,
&&9& 9    ,
&&&
.$
!## c  = = d exposed d2 e b k e2 e l n note 1 1 2 2 1 n a a1 a3 top view bottom view pad 
   

  * ,1 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 169 pic16f627a/628a/648a )
  - .  $  
,/ 0  121   -. 3 * &''  (  / *   3
& '
!&" & 4# *!( !!& 
  4 %&

&#& && 255***'
  
'5 4 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 170 ? 2009 microchip technology inc. notes: downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 171 pic16f627a/628a/648a appendix a: data sheet revision history revision a this is a new data sheet. revision b revised 28-pin qfn pin diagram revised figure 5-4 block diagram revised register 7-1 tmr1on revised example 13-4 data eeprom refresh routine revised instruction set subwf, example 1 revised dc characteristics 17-2 and 17-3 revised tables 17-4 and 17-6 corrected table and figure numbering in section 17.0 revision c general revisions throughout. revisions to section 14.0 C special features of the cpu. section 18, modified graphs. revision d revise example 13-2, data eeprom write revise sections 17.2, param no. d020 and 17.3, param no. d020e revise section 18.0 graphs revision e section 19.0 packaging information: replaced package drawings and added note. revision f (03/2007) replaced package drawings (rev. am); replaced development support section; revised product id system. revision g (10/2009) corrected 28-lead qfn package in section 19.1. appendix b: device differences the differences between the pic16f627a/628a/648a devices listed in this data sheet are shown in table b-1. table b-1: device differences device memory flash program ram data eeprom data pic16f627a 1024 x 14 224 x 8 128 x 8 pic16f628a 2048 x 14 224 x 8 128 x 8 pic16f648a 4096 x 14 256 x 8 256 x 8 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 172 ? 2009 microchip technology inc. appendix c: device migrations this section describes the functional and electrical specification differences when migrating between functionally similar devices. (such as from a pic16f627 to a pic16f627a). c.1 pic16f627/628 to a pic16f627a/ 628a 1. er mode is now rc mode. 2. code protection for the program memory has changed from code-protect sections of memory to code-protect of the whole memory. the configuration bits cp0 and cp1 in the pic16f627/628 do not exist in the pic16f627a/ 628a. they have been replaced with one configuration bit<13> cp . 3. brown-out detect (bod) terminology has changed to brown-out reset (bor) to better represent the function of the brown-out circuitry. 4. enabling brown-out reset (bor) does not automatically enable the power-up timer (pwrt) the way it did in the pic16f627/628. 5. intrc is now called intosc. 6. timer1 oscillator is now designed for 32.768 khz operation. in the pic16f627/628, the timer1 oscillator was designed to run up to 200 khz. 7. the dual-speed oscillator mode only works in the intosc oscillator mode. in the pic16f627/ 628, the dual-speed oscillator mode worked in both the intrc and er oscillator modes. appendix d: migrating from other pic ? devices this discusses some of the issues in migrating from other pic mcu devices to the pic16f627a/628a/ 648a family of devices. d.1 pic16c62x/ce62x to pic16f627a/ 628a/648a migration see microchip web site for availability (www.microchip.com). d.2 pic16c622a to pic16f627a/628a/ 648a migration see microchip web site for availability (www.microchip.com). note: this device has been designed to perform to the parameters of its data sheet. it has been tested to an electrical specification designed to determine its conformance with these parameters. due to process differences in the manufacture of this device, this device may have different performance characteristics than its earlier version. these differences may cause this device to perform differently in your application than the earlier version of this device. downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 173 pic16f627a/628a/648a the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: product support C data sheets and errata, application notes and sample programs, design resources, users guides and hardware support documents, latest software releases and archived software general technical support C frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing business of microchip C product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchips customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: distributor or representative local sales office field application engineer (fae) technical support development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 174 ? 2009 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in whic h our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this docume nt. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds40044g pic16f627a/628a/648a 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document? downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 175 pic16f627a/628a/648a index a a/d special event trigger (ccp)....................................... 59 absolute maximum ratings .............................................. 135 addlw instruction ........................................................... 119 addwf instruction ........................................................... 119 andlw instruction ........................................................... 119 andwf instruction ........................................................... 119 architectural overview ........................................................ 11 assembler mpasm assembler................................................... 132 b baud rate error .............................................. .................... 75 baud rate formula ........................................... .................. 75 bcf instruction ................................................................. 120 block diagrams comparator i/o operating modes .......................................... 64 modified comparator output .............................. 66 i/o ports rb0/int pin ........................................................ 38 rb1/rx/dt pin ................................................... 39 rb2/tx/ck pin ................................................... 39 rb3/ccp1 pin .................................................... 40 rb4/pgm pin ..................................................... 41 rb5 pin............................................................... 42 rb6/t1oso/t1cki pin ...................................... 43 rb7/t1osi pin ................................................... 44 rc oscillator mode................................................... 101 usart receive.......................................................... 82 usart transmit......................................................... 80 brgh bit........................................................................... .. 75 brown-out reset (bor) ................................................... 103 bsf instruction ................................................................. 12 0 btfsc instruction............................................................. 120 btfss instruction ............................................................. 121 c c compilers mplab c18 .............................................................. 132 call instruction ............................................................... 121 capture (ccp module) ............................................... ........ 58 block diagram............................................................. 58 ccp pin configuration................................................ 58 ccpr1h:ccpr1l registers...................................... 58 changing between capture prescalers...................... 58 prescaler..................................................................... 58 software interrupt ....................................................... 5 8 timer1 mode selection ............................................. .. 58 capture/compare/pwm (ccp)........................................... 57 capture mode. see capture ccp1 .......................................................................... 57 ccpr1h register............................................... 57 ccpr1l register ............................................... 57 ccp2 .......................................................................... 57 compare mode. see compare pwm mode. see pwm timer resources......................................................... 57 ccp1con register ............................................................ 57 ccp1m bits ................................................................ 57 ccp1x:ccp1y bits .................................................... 57 ccp2con register ccp2m<3:2> bits ....................................................... 57 ccp2x:ccp2y bits.................................................... 57 clocking scheme/instruction cycle ............................. ....... 15 clrf instruction............................................................... 12 1 clrw instruction.............................................................. 122 clrwdt instruction......................................................... 122 cmcon register.............................................................. .. 63 code examples data eeprom refresh routine ................................ 94 code protection ............................................... ................. 113 comf instruction.............................................................. 122 comparator block diagrams i/o operating modes .......................................... 64 modified comparator output .............................. 66 comparator module.............................................. ...... 63 configuration ....................................................... ....... 64 interrupts .................................................................... 67 operation.................................................................... 65 reference ................................................................... 65 compare (ccp module) ............................................... ...... 58 block diagram ............................................................ 58 ccp pin configuration ........................................... .... 59 ccpr1h:ccpr1l registers ..................................... 58 software interrupt .................................................. ..... 59 special event trigger ................................................. 5 9 timer1 mode selection............................................ ... 59 config register ............................................................... 98 configuration bits .................................................... ........... 97 crystal operation................................................................ 99 customer change notification service............................. 173 customer notification service .......................................... 173 customer support............................................... .............. 173 d data eeprom memory...................................................... 91 eecon1 register ...................................................... 91 eecon2 register ...................................................... 91 operation during code protection ............................. 95 reading .................................................. .................... 93 spurious write protection ........................................... 93 using .......................................................................... 94 write verify ................................................................. 93 writing to .................................................................... 9 3 data memory organization....................................... .......... 17 decf instruction .............................................................. 122 decfsz instruction.......................................................... 123 development support ................................................... .... 131 device differences.......................................................... .. 171 device migrations ............................................................. 172 dual-speed oscillator modes.......................................... .. 101 e eecon1 register...................................................... ......... 92 eecon1 register .............................................................. .. 92 eecon2 register .............................................................. .. 92 errata .................................................................. .................. 5 external crystal oscillator circuit ............................ ......... 100 f fuses. see configuration bits g general-purpose register file .......................................... . 17 goto instruction.............................................................. 123 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 176 ? 2009 microchip technology inc. i i/o ports .............................................................................. 33 bidirectional ................................................. ............... 46 block diagrams rb0/int pin ........................................................ 38 rb1/rx/dt pin ................................................... 39 rb2/tx/ck pin ................................................... 39 rb3/ccp1 pin .................................................... 40 rb4/pgm pin...................................................... 41 rb5 pin............................................................... 42 rb6/t1oso/t1cki pin ...................................... 43 rb7/t1osi pin ................................................... 44 porta........................................................................ 33 portb........................................................................ 38 programming considerations ..................................... 46 successive operations ............................................... 4 6 trisa ......................................................................... 33 trisb ......................................................................... 38 id locations ...................................................................... 113 incf instruction ................................................................ 124 incfsz instruction............................................................ 124 in-circuit serial programming? ....................................... 114 indirect addressing, indf and fsr registers.................... 30 instruction flow/pipelining .................................................. 15 instruction set addlw ..................................................................... 119 addwf ..................................................................... 119 andlw ..................................................................... 119 andwf ..................................................................... 119 bcf ........................................................................... 120 bsf ........................................................................... 120 btfsc ...................................................................... 120 btfss ...................................................................... 121 call ......................................................................... 121 clrf......................................................................... 121 clrw ....................................................................... 122 clrwdt................................................................... 122 comf ....................................................................... 122 decf ........................................................................ 122 decfsz.................................................................... 123 goto ....................................................................... 123 incf.......................................................................... 124 incfsz ..................................................................... 124 iorlw ...................................................................... 125 iorwf ...................................................................... 125 movf........................................................................ 125 movlw .................................................................... 125 movwf .................................................................... 126 nop .......................................................................... 126 option .................................................................... 126 retfie ..................................................................... 126 retlw ..................................................................... 127 return ................................................................... 127 rlf ........................................................................... 127 rrf........................................................................... 128 sleep ...................................................................... 128 sublw ..................................................................... 128 subwf ..................................................................... 129 swapf ..................................................................... 129 tris.......................................................................... 129 xorlw ..................................................................... 130 xorwf..................................................................... 130 instruction set summary................................................... 117 int interrupt ...................................................................... 110 intcon register ................................................................ 26 internet address ................................................... ............ 173 interrupt sources capture complete (ccp)............................................ 58 compare complete (ccp).......................................... 59 tmr2 to pr2 match (pwm) ....................................... 60 interrupts........................................................................... 10 9 interrupts, enable bits ccp1 enable (ccp1ie bit) ........................................ 58 interrupts, flag bits ccp1 flag (ccp1if bit)............................................. 58 iorlw instruction .......................................................... .. 125 iorwf instruction ............................................................ 1 25 m memory organization data eeprom memory.................................. 91, 93, 95 microchip internet web site.............................................. 173 migrating from other picmicro devices ............................ 17 2 movf instruction.............................................................. 125 movlw instruction......................................................... .. 125 movwf instruction .......................................................... 126 mplab asm30 assembler, linker, librarian ................... 132 mplab integrated development environment software.. 131 mplab pm3 device programmer .................................... 134 mplab real ice in-circuit emulator system ................ 133 mplink object linker/mplib object librarian ................ 132 n nop instruction .............................................................. .. 126 o option instruction .......................................................... 1 26 option register............................................................ .... 25 option_reg register...................................................... 25 oscillator configurations..................................................... 99 oscillator start-up timer (ost) ........................................ 103 p package marking information .................................... ....... 163 packaging information .................................................... .. 163 pcl and pclath................................................ ............... 30 stack.................................................................. ......... 30 pcon register ................................................................... 29 pie1 register.......................................................... ............ 27 pin functions rc6/tx/ck .............................................. ............. 73C89 rc7/rx/dt............................................... ............ 73C89 pir1 register ................................................................. .... 28 porta ............................................................................... 33 portb ............................................................................... 38 portb interrupt ............................................................. .. 110 power control/status register (pcon).......................... .. 104 power-down mode (sleep)............................................... 112 power-on reset (por) ............................................. ....... 103 power-up timer (pwrt) .................................................. 1 03 pr2 register .......................................................... ...... 54, 60 program memory organization.......................................... . 17 pwm (ccp module) .............................................. ............. 60 block diagram ............................................................ 6 0 simplified pwm .................................................. 60 ccpr1h:ccpr1l registers...................................... 60 duty cycle .................................................................. 61 example frequencies/resolutions ............................. 61 period ......................................................................... 60 set-up for pwm operation......................................... 6 1 tmr2 to pr2 match ................................................... 60 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 177 pic16f627a/628a/648a q q-clock ............................................................................... 61 quick-turnaround-production (qtp) devices ...................... 9 r rc oscillator..................................................................... 101 rc oscillator mode block diagram........................................................... 101 reader response ................................................. ............ 174 registers ccp1con (ccp operation)....................................... 57 cmcon (comparator configuration).......................... 63 config (configuration word).................................... 98 eecon1 (eeprom control register 1) .................... 92 intcon (interrupt control)......................................... 26 maps pic16f627a ................................................ . 18, 19 pic16f628a ................................................ . 18, 19 option_reg (option) .............................................. 25 pcon (power control) ............................................... 29 pie1 (peripheral interrupt enable 1)........................... 27 pir1 (peripheral interrupt register 1) ........................ 28 status.......................................................................... 24 t1con timer1 control).............................................. 50 t2con timer2 control).............................................. 55 reset................................................................................. 101 retfie instruction............................................................ 126 retlw instruction ............................................................ 127 return instruction ......................................................... 127 revision history ................................................................ 171 rlf instruction.................................................................. 127 rrf instruction ................................................................. 128 s serial communication interface (sci) module, see usart serialized quick-turnaround-production (sqtp) devices ... 9 sleep instruction ............................................................. 128 software simulator (mplab sim)..................................... 133 special event trigger. see compare special features of the cpu .............................................. 97 special function registers ................................................. 20 status register ................................................................... 24 sublw instruction............................................................ 128 subwf instruction ........................................................... 129 swapf instruction............................................................ 129 t t1ckps0 bit ....................................................................... 50 t1ckps1 bit ....................................................................... 50 t1con register ................................................................. 50 t1oscen bit ...................................................................... 50 t2ckps0 bit ....................................................................... 55 t2ckps1 bit ....................................................................... 55 t2con register ................................................................. 55 timer0 block diagrams timer0/wdt ....................................................... 48 external clock input.............................................. ...... 47 interrupt....................................................................... 47 prescaler..................................................................... 48 switching prescaler assignment................................. 49 timer0 module .............................................. .............. 47 timer1 asynchronous counter mode ..................................... 52 capacitor selection............................................ ......... 53 external clock input .............................................. ..... 51 external clock input timing........................................ 5 2 oscillator..................................................................... 53 prescaler .............................................................. 51, 53 resetting timer1 ........................................................ 53 resetting timer1 registers ........................................ 53 special event trigger (ccp) ...................................... 59 synchronized counter mode ...................................... 51 timer mode ................................................................ 51 tmr1h ....................................................................... 5 2 tmr1l........................................................................ 52 timer2 block diagram ............................................................ 54 postscaler................................................................... 54 pr2 register................................................................ 54 prescaler .............................................................. 54, 61 timer2 module.............................................. .............. 54 tmr2 output ............................................................... 54 tmr2 to pr2 match interrupt..................................... 60 timing diagrams timer0 ...................................................................... 147 timer1 ...................................................................... 147 usart asynchronous receiver...................................... 83 usart asynchronous master transmission ............. 80 usart asynchronous reception .............................. 83 usart synchronous reception ................................ 89 usart synchronous transmission ........................... 87 timing diagrams and specifications ................................ 144 tmr0 interrupt.............................................................. .... 110 tmr1cs bit ........................................................................ 5 0 tmr1on bit........................................................................ 5 0 tmr2on bit........................................................................ 5 5 toutps0 bit .................................................................... .. 55 toutps1 bit .................................................................... .. 55 toutps2 bit .................................................................... .. 55 toutps3 bit .................................................................... .. 55 tris instruction ............................................................ .... 129 trisa ................................................................................. 33 trisb ................................................................................. 38 u universal synchronous asynchr onous receiver transmitter (usart) ..................................................................... 73 asynchronous receiver setting up reception.......................................... 85 asynchronous receiver mode address detect ................................................... 85 block diagram .................................................... 85 usart asynchronous mode................................................ ... 79 asynchronous receiver.............................................. 82 asynchronous reception............................................ 84 asynchronous transmission ...................................... 80 asynchronous transmitter......................................... . 79 baud rate generator (brg) ...................................... 75 block diagrams transmit.............................................................. 80 usart receive ................................................. 82 brgh bit .................................................................... 75 sampling......................................................... 76, 77, 78 synchronous master mode......................................... 86 synchronous master reception ................................. 88 synchronous master transmission ............................ 86 synchronous slave mode........................................... 89 synchronous slave reception ................................... 90 downloaded from: http:///
pic16f627a/628a/648a ds40044g-page 178 ? 2009 microchip technology inc. synchronous slave transmit ...................................... 89 v voltage reference configuration............................................................... 69 voltage reference module ......................................... 69 w watchdog timer (wdt) ......................................... ........... 111 www address.................................................................. 173 www, on-line support..................................... ................... 5 x xorlw instruction ........................................................... 130 xorwf instruction ........................................................... 130 downloaded from: http:///
? 2009 microchip technology inc. ds40044g-page 179 pic16f627a/628a/648a product identification system to order or obtain information, e.g., on pricing or delivery, refer to the factory or the listed sales office. part no. x /xx xxx pattern package temperature range device device: pic16f627a/628a/648a:standard v dd range 3.0v to 5.5v pic16f627a/628a/648at:v dd range 3.0v to 5.5v (tape and reel) pic16lf627a/628a/648a:v dd range 2.0v to 5.5v pic16lf627a/628a/648at:v dd range 2.0v to 5.5v (tape and reel) temperature range: i= -40 c to +85 c e=-40 c to+125 c package: p=pdip so = soic (gull wing, 7.50 mm body) ss = ssop (5.30 mm ml = qfn (28 lead) examples: a) pic16f627a - e/p 301 = extended te m p . , pdip package, 20 mhz, normal v dd lim- its, qtp pattern #301. b) pic16lf627a - i/so = industrial temp., soic package, 20 mhz, extended v dd limits. downloaded from: http:///
ds40044g-page 180 ? 2009 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4080 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-6578-300 fax: 886-3-6578-370 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 03/26/09 downloaded from: http:///


▲Up To Search▲   

 
Price & Availability of PIC16F648A-ISOC06

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X